-
Notifications
You must be signed in to change notification settings - Fork 0
/
21 stcks_game
38 lines (28 loc) · 915 Bytes
/
21 stcks_game
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
import random
def main():
sticks = 21
print("From 21 sticks, choose to take 1-3 sticks at a time.")
print("The one who takes the last stick winer.")
player1 = input("Enter name of Player 1: ")
player2 = input("Enter name of Player 2: ")
current_player = player1
while True:
print("sticks in the pile:", sticks)
sticks_taken = int(input(f"{current_player}, take sticks (1-3): "))
if sticks_taken < 1 or sticks_taken > 3:
print("Invalid choice, you must take between 1 and 3 sticks.")
continue
else:
sticks_taken = random.randint(1, 3)
print(f"{current_player} takes {sticks_taken} sticks.")
sticks -= sticks_taken
if sticks <= 0:
print(f"{current_player} took the last stick. {current_player} Winner!")
break
# Switch player
if current_player == player1:
current_player = player2
else:
current_player = player1
if __name__ == "__main__":
main()