-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathr_p_s.py
More file actions
27 lines (19 loc) · 808 Bytes
/
r_p_s.py
File metadata and controls
27 lines (19 loc) · 808 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import random
def rock_paper_scissors():
player = input("What is your choice - 'r' for rock, 's' for scissor, 'p' for paper: ")
choices = ['r','s','p']
opponent = random.choice(choices)
if player == opponent:
return print(f"Its a Tie! Choice is {opponent}")
if check_win(player, opponent):
return print(f"Yay! you won! Choice is {opponent}")
if check_win(player, opponent) != True:
return print(f"You lost! Choice is {opponent}")
def check_win(user, computer):
if (user == 'r' and computer == 's') or (user == 's' and computer == 'p') or (user == 'p' and computer == 'r'):
return True
rock_paper_scissors()
'''
What is your choice - 'r' for rock, 's' for scissor, 'p' for paper: r
You lost! Choice is p
'''