Untitled
unknown
python
3 years ago
2.3 kB
9
Indexable
import random def RPS_game() -> str: """ This function is used to start the Rock, Paper and Scissor game Parameters: The game takes in no arguments. Returns: The function has no return value as the type of the function is void. Return type: Void """ #In the line below a random choice between RPS is made for the comp player. comp_choice = random.choice(["rock", "paper", "scissors"]) #In the line below input is taken from the player. player_choice = input("Choose rock, paper, or scissors: ") #In the line below we are checking if the player input is valid if not (is_legal(player_choice)): print("You must select from rock, paper, or scissors") #if not checks for false value from the is_legal function else: print("The computer chose", comp_choice) if beats(player_choice, comp_choice): print("You win!") elif beats(comp_choice, player_choice): print("You lost. :(") #Neither of the above is true so this else is executed else: print("It's a tie.") def is_legal(player_choice : str) -> bool: """ This function is used to check wheather the player choice is valid Parameters: player_choice::str The variable which stores the player input. Returns: The function returns a boolean value. Return type: Bool """ if(player_choice == "rock" or player_choice == "scissors" or player_choice == "paper"): return True else: return False def beats(player_one:str,player_two:str) -> bool: """ This function is used to check who won between the player and the comp Parameters: player_one::str The variable which stores the player one input. player_two::str The variable which stores the player two input. Returns: The function returns a boolean value. Return type: Bool """ if(player_one == "rock" and player_two=="scissor"): return True elif(player_one == "paper" and player_two=="rock"): return True elif(player_one == "scissors" and player_two=="paper"): return True else: return False
Editor is loading...