-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathblkbean.py
More file actions
executable file
·55 lines (47 loc) · 1.24 KB
/
blkbean.py
File metadata and controls
executable file
·55 lines (47 loc) · 1.24 KB
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
#!/usr/bin/python3
##
## Black bean game.
## Rus with Python3.
## Author: Aiden Woodruff <aiden.woodruff@gmail.com>
##
import random
import time
print("Whoever takes the last bean wins")
total_beans = int(input("How many total beans: "))
max_beans = int(input("Max beans per turn: "))
## Disabled so computer always wins
# turn_s = input("Would you like to go first? (Y/N): ")
# if (turn_s == "Y" or turn_s == "y"):
# turn = 1
# else:
# turn = 0
if total_beans % (max_beans+1) == 0:
turn = 1
else:
turn = 0
num_beans = total_beans
while (num_beans > 0):
take = 0
print(num_beans, " beans left.")
if (turn == 0):
print("My turn!")
if (num_beans % (max_beans+1) > 0):
take = num_beans % (max_beans+1)
else:
take = random.randint(1,max_beans)
time.sleep(1)
print("I take ", take, " beans.")
elif (turn == 1):
print("Your turn!")
while (not(take >= 1 and take <= max_beans)):
take = int(input("Take how many beans: "))
print("You take ", take, " beans.")
num_beans -= take
if (turn ==0):
turn = 1
elif (turn == 1):
turn = 0
if (turn == 0):
print("I lose! :(")
elif (turn == 1):
print("You lose! :)")