I am fairly new to python and I am trying to make a rock, paper, scissors game, with one player vs the computer. I have made a dictionary for the winning conditions and a function for the PC to choose its random option from said dictionary. This is my code so far (not finished yet but it is what I have done so far):
import random
WinConditions = {"paper":"rock", "scissors":"paper", "rock":"scissors"}
def Player():
selection = input ("Write Rock, Paper or Scissors and Press Enter.")
if selection.lower() not in WinConditions.keys():
print ("You did not select a valid option!")
Player()
else:
return selection
def PC():
PCselection = random.choice((list(WinConditions.keys()))
return (PCselection)
def rock_paper_scissors():
Player1 = Player()
Computer = PC()
The first problem I have encountered is on the PC() function, it gives my Syntax Error on the return part. Why is that?
Aucun commentaire:
Enregistrer un commentaire