所以我刚刚开始研究这个来练习我的递归经验。我在这里有我的代码,由于某种原因它只允许我使用其中的提款部分而不是存款:
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()
请让我知道我的错误!
最佳答案
你应该改变:
if option == "withdraw" or "Withdraw":
至:
if option == "withdraw" or option == "Withdraw":
并对存款
执行相同的操作。
关于python - 递归取款和存款,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30146676/