退出循环时如何获得 balance 的新值?现在它只取原始值并打印它。我也试过 balance += (balance + dep)
balance = 500
def main(balance):
if balance <= 999999:
intrest = 0.01
if balance >= 1000000:
intrest = 0.02
menu = int(input('Press 1 for balance, 2 for deposit, 3 for withdrawal or 4 for interest return: '))
if menu == 1:
print(balance)
elif menu == 2:
dep = int(input('How much do you want to deposit? '))
balance = (balance + dep)
print('Your new balance is', balance)
if balance <= 999999:
intrest = 0.01
if balance >= 1000000:
intrest = 0.02
print('Congratulations, your intrest just went up!')
elif menu == 3:
wit = int(input('How much do you want to withdraw? '))
balance = (balance - wit)
print('Your new balance is', balance)
if balance <= 999999:
intrest = 0.01
print('Your intrest is now back to standard!')
elif menu == 4:
intrest_return = balance + (balance * intrest)
print(intrest_return)
while True:
restart = str(input('Would you like to do more? Press y for yes or n for no: '))
if restart == 'y':
main(balance)
else:
break
main(balance)
print(balance)
三国纷争
慕田峪7331174
相关分类