forked from tiyd-python-2015-05/game-of-sticks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsticks.py
60 lines (45 loc) · 1.33 KB
/
sticks.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
def game():
sticks = 10
current_player = turn()
while sticks != 0:
choice = pick_up_sticks(sticks)
sticks -= choice
current_player = switch_players(current_player)
print("{} sticks left!".format(sticks))
print("{} is the winner!".format(current_player))
return
def turn(current_player='player1'):
print(current_player)
return current_player
def switch_players(current_player):
if current_player == 'player1':
current_player = 'player2'
else:
current_player = 'player1'
print("{}'s turn".format(current_player))
return current_player
def pick_up_sticks(sticks):
choice = \
input("How many sticks do you want to pick up?: ")
while not is_choice_valid(choice, sticks):
return pick_up_sticks(sticks)
choice = int(choice)
return choice
def is_choice_valid(choice,sticks):
if not choice.isnumeric():
print("You typed something weird")
return False
elif int(choice) > 3 or int(choice) < 1:
print("You entered an invalid amount.")
return False
elif int(choice) > sticks:
print("There isn't that many sticks left")
return False
else:
return True
# def is_there_a_winner(sticks):
# if sticks == 0:
# return
game()
if __name__ == '__main__':
pass