-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnimm.py
More file actions
32 lines (29 loc) · 938 Bytes
/
nimm.py
File metadata and controls
32 lines (29 loc) · 938 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
32
"""
File: nimm.py
-------------------------
Add your comments here.
"""
def main():
player = 1
total_stones = 20
print('There are 20 stones left')
while total_stones > 0:
user_answer = int(input("Player " + str(player) + " would you like to remove 1 or 2 stones? "))
print("")
while user_answer <= 0 or user_answer > 2:
user_answer = int(input("Please enter 1 or 2: "))
if user_answer == 1:
print("There are " + str(total_stones-1) + " stones left")
total_stones -= 1
else:
print("There are " + str(total_stones-2) + " stones left")
total_stones -= 2
if player == 1:
player = 2
else:
player = 1
print("Game over! Player " +str(player) + " wins!")
# This provided line is required at the end of a Python file
# to call the main() function.
if __name__ == '__main__':
main()