forked from NBHS-STEM/hundred_game
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
31 lines (24 loc) · 695 Bytes
/
main.py
File metadata and controls
31 lines (24 loc) · 695 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
28
29
30
31
import itertools
import os
# Instructions & setup
os.system('clear')
print("This is the 💯 game - on your turn you'll choose a whole number between 1 and 10 to add to the shared total.\nWhichever player reaches 100 first wins the game!\n")
total = 0
player = itertools.cycle('12')
# Game loop
while True:
player_num = next(player)
# Validation loop
while True:
print(f"\nThe current total is {total}.")
try:
step = int(input(f"Player {player_num}, choose a number between 1 and 10 to add: "))
if not (1 <= step <= 10):
raise ValueError
break
except ValueError:
print("Invalid entry")
total += step
if total >= 100:
print(f"Player {player} wins!")
break