(I added the function in question @ Bottom)
Working on my first python app.
Im making a simple rock, paper, scissors game.
I have a function that takes in two parameters:
- The users input
- The computers input
The function looks like this:
seeIfUserWon(userInput, selectRandomOption()) where selectRandomOption() just chooses a random Enum (ROCK, PAPER, SCISSORS)
The code works if I replace selectRandomOption with hardcoded input.
Currently that code gives me the error:
ValueError: 'Paper' is not a valid RPS where RPS is an Enum class with 3 cases: ROCK, PAPER, SCISSORS
But like I said if I just put in RPS.ROCK for the second parameter then it works...
What am I not understanding about python.. maybe I need to use a lambda here but I'm not sure? Any references would be appreciated as well!
Functions I used:
def selectRandomOption() -> RPS:
pick = options[random.randint(0,2)]
return RPS(pick)
Options:
options = ["Rock", "Paper", "Scissors"]
Which I then validate with:
def validateUserInput(input):
if "rock" in input.lower():
return RPS.ROCK
elif "paper" in input.lower():
return RPS.PAPER
elif "scissors" in input.lower():
return RPS.SCISSORS
else:
raise Exception
Enum :
class RPS(Enum):
ROCK = auto()
PAPER = auto()
SCISSORS = auto()