-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.py
74 lines (56 loc) · 1.65 KB
/
functions.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import random
from headers import *
options = ['rock', 'paper', 'scissors']
def choose_mode():
while True:
mode = input('Which mode would you like to play?'
'\n[1] Best of 3'
'\n[2] Indefinite Mode'
'\n[3] Custom Number of Rounds'
'\n[4] Quit\n')
if mode == '4':
print('Goodbye!')
exit()
elif mode in ['1', '2', '3']:
return mode
else:
print('Please enter 1, 2, or 3. Or enter 4 to quit')
def user_choice():
while True:
user_input = input('Which do you choose: ROCK / PAPER / SCISSORS or Q to quit: ').strip().lower()
if user_input in ['q', 'quit']:
print('Goodbye!')
exit()
elif user_input not in options:
print('Please enter a valid option')
continue
else:
break
return user_input
def cpu_choice():
random_number = random.randint(0, 2)
cpu = options[random_number]
return cpu
def user_wins(user, cpu):
if user == 'rock' and cpu == 'scissors':
return True
elif user == 'paper' and cpu == 'rock':
return True
elif user == 'scissors' and cpu == 'paper':
return True
else:
return False
def wants_to_play_again():
while True:
again = input('Play again? y/n: ').lower().strip()
if again == 'y':
return True
elif again == 'n' or 'q':
return False
else:
print('Please enter either y or n')
def is_odd(num):
if num % 2 == 1:
return True
else:
return False