From f2ba9a39a671aa1c9cb129d6917cb7ce5414509d Mon Sep 17 00:00:00 2001 From: Abderahmane <88046593+abdouZent@users.noreply.github.com> Date: Tue, 27 Jul 2021 17:43:09 +0200 Subject: [PATCH] Update to rock_paper_scissors.py --- rock_paper_scissors.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/rock_paper_scissors.py b/rock_paper_scissors.py index a9624d8..c4210ed 100644 --- a/rock_paper_scissors.py +++ b/rock_paper_scissors.py @@ -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: @@ -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())