-
Notifications
You must be signed in to change notification settings - Fork 0
/
rock_paper_scissors.py
57 lines (41 loc) · 1.17 KB
/
rock_paper_scissors.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
50
51
52
53
54
55
56
57
import random
def rps(y):
game_dict= {1: 'rocks', 2:'paper', 3:'scissors'}
x = random.choice([1, 2, 3])
outcome = y - x
feedback = f'You played {game_dict.get(y)}, the computer played {game_dict.get(x)}.'
if outcome in [-2, 1]:
print(f'{feedback}\nYou win!')
elif outcome in [-1, 2]:
print(f'{feedback}\nComputer win!.')
else:
print(f'{feedback}\nIt\'s a tie!')
def play_again():
try:
again = input('Would you like to play again (y)es or (n)o? ')
if again not in ['y', 'n']:
raise ValueError
except Exception:
print('\nError: wrong input!')
play_again()
else:
if again == 'y':
main ()
else:
print('Good bye!')
def main():
try:
y= int(input(' Choose (1) for rocks, (2) for paper, or (3) for scissors: '))
if y <1 or y > 3:
raise ValueError
except ValueError:
print('\nERROR: wrong input!!! Try again.')
main()
else:
rps(y)
finally:
play_again()
if __name__== '__main__':
pass
import rps
rps.main()