I have tried to create the program to play "Rock, Paper, Scissors, Lizard & Spock", as I had done to create the simple game of "Rock, paper, Scissors", however I cannot with the prompts they asked me:
In addition, it should also improve the way the game interacts with the player: the number of rounds to play, which must be an odd number, will be requested from the user until a valid number is entered. Define a new function to make that request.
Could you help me please? this is the code i used:
import random
gestures = ['rock', 'paper', 'scissors', 'lizard', 'spock']
n_rounds = 0
cpu_score = 0
player_score = 0
import random
gestures = ['rock', 'paper', 'scissors', 'lizard', 'spock']
n_rounds = 0
cpu_score = 0
player_score = 0
def rounds_to_win(gestures):
rounds_to_win = print("How many rounds you want to play? Introduce an odd number")
while rounds_to_win %2 == 0:
if rounds_to_win % 2 > 0:
print("This isn't a valid option. Introduce an odd numbe")
elif rounds_to_win %2 < 0:
print("You chose", rounds_to_win)
def cpu_choice (gestures):
return random.choice(gestures)
def player_choice(gestures):
player_choice = input("Stone, paper, scissors, lizard or spock?. Please, type your choice.")
while player_choice not in gestures:
player_choice = input("That's not an option. Stone, paper, scissors, lizard or spock?")
if player_choice == "stone":
print("You choose stone")
elif player_choice == "paper":
print("You choose paper")
elif player_choice == "scissors":
print("You choose scissor")
elif player_choice == "lizard":
print("You choose lizard")
elif player_choice == "spock":
print("You choose Spock")
return str(player_choice)
def choice(gestures):
print("You chose:", player_choice)
print("CPU chose:", cpu_choice)
if player_choice == "stone" and cpu_choice == "stone":
print("Stone vs stone. It's a tie")
cpu_score += 0
player_score += 0
n_rounds += 1
elif player_choice == "paper" and cpu_choice == "paper":
print("Paper vs paper. It's a tie")
cpu_choice += 0
player_score += 0
n_rounds += 1
elif player_choice == "scissors" and cpu_choice == "scissors":
print("Scissors vs scissors. It's a tie")
cpu_score += 0
player_score += 0
n_rounds += 1
elif player_choice == "stone" and cpu_choice == "paper":
print("Stone vs paper. You loose")
cpu_score += 0
player_score += 2
n_rounds += 1
elif player_choice == "stone" and cpu_choice == "scissors":
print("Stone vs scissors. You win")
cpu_choice += 1
player_score += 0
n_rounds += 1
elif player_choice == "paper" and cpu_choice == "stone":
print("Paper vs stone. You win")
cpu_score += 0
player_score += 2
n_rounds += 1
elif player_choice == "paper" and cpu_choice == "scissors":
print("Paper vs Scissors. You loose")
cpu_choice += 1
player_score += 0
n_rounds += 1
elif player_choice == "scissors" and cpu_choice == "paper":
print("Scissors vs paper. You win")
cpu_score += 0
player_score += 2
n_rounds += 1
elif player_choice == "scissors" and cpu_choice == "stone":
print("Scissors vs stone. You loose")
cpu_choice += 1
player_score += 0
n_rounds += 1
def winner():
print((player_score) - (cpu_score))
while n_rounds < 5:
rounds_to_win(gestures)
player_choice(gestures)
cpu_choices = cpu_choice(gestures)
winner()
if player_score > cpu_score:
print("You won")
else:
print("CPU won")