所以我刚刚开始研究这种方法来练习递归的经验。我在这里有我的代码,由于某种原因它只允许我使用它的提款部分而不是存款:
def recursive(n):
print("You have $", n, "In the bank!")
option = (input("Do you want to withdraw or deposit?"))
if option == "withdraw" or "Withdraw":
withdraw = int(input("How much do you want to withdraw from your account?"))
recursive(n - withdraw)
elif option == "deposit" or "Deposit":
deposit = int(input("How much do you want to deposit?"))
recursive(n + deposit)
else:
print("Not a valid option!")
print("Shutting Down!")
def money(n):
if n < 0:
print("You are out of money!")
def main():
recursive(100)
main()
请在这里告诉我我的错误!
答案 0 :(得分:2)
你应该改变:
if option == "withdraw" or "Withdraw":
为:
if option == "withdraw" or option == "Withdraw":
也为deposit
做同样的事情。