-
Notifications
You must be signed in to change notification settings - Fork 0
/
r_p_s.py
53 lines (39 loc) · 1.38 KB
/
r_p_s.py
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
3 r p s
import random
def play():
user = input('(r) for rock, (p) for paper, (s) for scissors: ')
computer = random.choice(['r','p','q'])
if user == computer:
return 'tie'
if is_win(user,computer): # if win == true
return 'You won!'
return 'lose man TT'
def is_win(player, opponent):
#return tru if user win
# 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
print(play())
import random
def play():
user = input('(r) for rock, (p) for paper, (s) for scissors: ')
computer = random.choice(['r','p','s'])
if user == computer:
again_not = input('ohoh ur so strong, wanna bea me again\n(ok) for continue, (no) for done: ')
if again_not == 'ok':
while user == computer:
user = input('(r) for rock, (p) for paper, (s) for scissors: ')
computer = random.choice([ 'r', 'p', 's' ])
else:
return 'tie'
if is_win(user, computer): # if win == true
return 'You won!'
return 'lose man TT'
def is_win(player, opponent):
# return tru if user win
# 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
print(play())