-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOdds and evens.py
51 lines (51 loc) · 1.24 KB
/
Odds and evens.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
import sys
import random
print("Odds and Evens, offline.")
def game():
try:
G = int(input("What number from 1 to 5? "))
except ValueError:
print("Please choose a number.")
game()
if G > 5 or G < 1:
print("Please enter a number from 1-5.")
game()
GEO = input("Odd or Even? ").lower()
if GEO != "odd" and GEO != "even":
print("Please enter 'Odd' or 'Even'.")
game()
AIG = random.randint(1,5)
AIGEO = random.randint(1,2)
if AIGEO == 1:
AIGEO = "even"
else:
AIGEO = "odd"
Total = G+AIG
print(f"""AI Number: {AIG}
AI Guess: {AIGEO}
Total of both Numbers: {Total}""")
if Total == 2 or Total == 4 or Total == 6 or Total == 8 or Total == 10:
WhatToExpect = "even"
else:
WhatToExpect = "odd"
if AIGEO == WhatToExpect and GEO == WhatToExpect:
print("Tie!")
elif AIGEO == WhatToExpect:
print("AI Wins!")
elif GEO == WhatToExpect:
print("Player Wins!")
else:
print("Nobody wins!")
def loop():
exit = input("Would you like to play again? ('Y' or 'N') ").upper()
if exit == "Y":
print("Okay! Restarting...")
game()
elif exit == "N":
print("Okay! Exiting...")
sys.exit(0)
else:
print("Please enter a valid option.")
loop()
loop()
game()