I'm trying to get my balance to add up but I don't know how to save my balance to a variable from a random number. In the screenshot below, it shows that they are giving and my balance does not add up.
import random
def main():
bank=0
backstory()
pet=input("what pet do you have? ")
print("nice! your pet will be a ", pet)
decisions(pet, bank)
#outcome()
def backstory():
print('You are a homeless person and are trying to get money to feed yourself and your pet.')
print('Everything you choose to do will effect how your outcome will be.')
print('You have five decisions you can make')
print('dont forget to eat or feed your pet so neither if you two will die!')
def decisions(animal,money):
print('enter "beg" to beg for money')
print('enter "work" to work for money')
print('enter "eat" to eat food')
print('enter "feed" to feed your pet')
print('enter "steal" to steal from someone!')
print('enter "skip" to do nothing and skip a decision for the day')
cont=0
bank=0
while cont<=4:
pick=input("what will be youre decision? ")
if pick=="beg":
beg(bank)
cont+=1
elif pick=="work":
work(money)
cont+=1
elif pick=="eat":
eat(money)
cont+=1
elif pick=="feed":
feed(money)
cont+=1
elif pick=="steal":
steal(money)
cont+=1
elif pick=="skip":
skip(money)
cont+=1
else:
print("sorry! thats not an option! please pick something from above")
#outcome(animal, money)
print("all done")
def beg(bank):
names=["Alvin and the Chipmunks", "Bob", "Timmy", "Alex", "Carah", "A very Rich Man"]
amount=random.randint(1,20)
print(random.choice(names), "gave you ", amount, "!")
bank=amount+bank
print("your balance is ", bank)
main()
Aucun commentaire:
Enregistrer un commentaire