2 回答
TA贡献1804条经验 获得超7个赞
您应该return在代码中使用 a ,然后将其分配给您的变量。这将是您的代码:
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
return balance
balance=main(balance)
print(balance)
添加回答
举报