Skip to content

Instantly share code, notes, and snippets.

@Gumnos
Created February 10, 2022 01:17
Show Gist options
  • Save Gumnos/8b6ab546ae968fa34d0b8fc07ffc2477 to your computer and use it in GitHub Desktop.
Save Gumnos/8b6ab546ae968fa34d0b8fc07ffc2477 to your computer and use it in GitHub Desktop.
Bookstore simulator
from random import randint
def d6():
return randint(1,6)
day = money = 0
time = patience = 10
while day < 10 and money < 10:
day += 1
print(f"Day #{day}")
while True:
roll = d6()
if d6() in (1,2,3): # customer
status = ["Customer"]
if roll == 1:
status.append("needs toilet")
patience -= 1
elif roll == 2:
status.append("shoplifts")
money -= 1
elif roll == 3:
status.append("wants book you don't have")
time -= 1
elif roll == 4:
status.append("is a literal wild animal")
time -= 1
elif roll == 5:
status.append("has a complaint")
patience -= 1
elif roll == 6:
status.append("buys a book!")
money += 1
else: # crisis
status = ["Crisis:"]
if roll == 1:
status.append("run out of tea")
patience -= 1
elif roll == 2:
status.append("printer broken")
time -= 2
elif roll == 3:
status.append("can't find book")
time -= 3
elif roll == 4:
status.append("haggling customer")
patience -= 3
elif roll == 5:
status.append("phone rings")
patience -= 1
time -= 1
elif roll == 6:
status.append("buy a book")
money -= 1
print(" ".join(status))
if money >= 10:
break
if patience <= 0:
print("Out of patience: new day")
time = patience = 10
break
if time <= 0:
print("Out of time: new day")
time = patience = 10
break
if money >= 10:
print("won!")
else:
print(f"Money: {money}")
print(f"Patience: {patience}")
print(f"Time: {time}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment