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
11 changes: 8 additions & 3 deletions rock_paper_scissors.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

def play():
user = input("What's your choice? 'r' for rock, 'p' for paper, 's' for scissors\n")
# if user choose a random alphabet that is either r, p or s
if user != 'r' and user != 'p' and user 's':
print("please choose either r, p or s! ")
continue
computer = random.choice(['r', 'p', 's'])

if user == computer:
Expand All @@ -27,9 +31,10 @@ def play():

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'):
# r > s, s > p, p > r
# po : rs , sp , pr
po = player + opponent
if (po == 'rs') or (po == 'sp') or (po == 'pr'):
return True

print(play())