I have a bank program where you can do multiple things, and the var balance needs to update based on user input. It does so the first time, and uses the new value in the next run. But if you run the loop a third time, it uses the balance output for the first run, and not the second. And if you run it a fourt time, it still uses the first value, and so on.
I am still very new to programming, but my theory is that the second loop cant return the new value of balance, so it just gets stuck on the first. But I don’t know how to work around that.
Does anyone here have any ideas? Thank you.
balance = 500
def main(balance):
menu = int(input('Press 1 for balance, 2 for deposit, 3 for withdrawal or 4 for interest return: '))
print()
if menu == 1:
print(balance)
elif menu == 2:
dep = int(input('How much do you want to deposit? '))
print()
balance = (balance + dep)
print('Your new balance is', balance)
print()
if balance <= 999999:
interest = 0.01
print('Your interest is standard, 0.01%')
if balance >= 1000000:
interest = 0.02
print('Your intrest is premium, 0.02%!')
elif menu == 3:
wit = int(input('How much do you want to withdraw? '))
print()
balance = (balance - wit)
print('Your new balance is', balance)
print()
if balance <= 999999:
interest = 0.01
print('Your intrest is standard, 0.01%')
if balance >= 1000000:
interest = 0.02
print('Your interest is premium, 0.02%!')
elif menu == 4:
if balance <= 999999:
interest = 0.01
if balance >= 1000000:
interest = 0.02
interest_return = (balance * interest)
balance = (balance + interest_return)
print('Your interest is', interest, 'that makes your intrest return', interest_return, 'and your new balance', balance)
return balance
balance = main(balance)
while True:
print()
restart = str(input('Would you like to do more? Press y for yes or n for no: '))
if restart == 'n':
print('Thank you for using the automatic bank service!')
break
elif restart == 'y':
main(balance)
else:
print()
print('Invalid input, press y for yes or n for no')
continue