Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions rock_paper_scissors.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,21 @@

def play():
user = input("What's your choice? 'r' for rock, 'p' for paper, 's' for scissors\n")

if user not in ['r', 'p', 's']:
return 'Invalid input. Please choose "r" for rock, "p" for paper, or "s" for scissors.'

computer = random.choice(['r', 'p', 's'])

if user == computer:
return 'It\'s a tie'
return "It's a tie"

# r > s, s > p, p > r
if is_win(user, computer):
return 'You won!'

return 'You lost!'

def is_win(player, opponent):
# return true if player wins
# r > s, s > p, p > r
if (player == 'r' and opponent == 's') or (player == 's' and opponent == 'p') \
or (player == 'p' and opponent == 'r'):
return True
Expand Down