python - 递归取款和存款

标签 python recursion

所以我刚刚开始研究这个来练习我的递归经验。我在这里有我的代码,由于某种原因它只允许我使用其中的提款部分而不是存款:

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/

相关文章:

javascript - 石头剪刀布递归

Javascript递归超时调用

python - 递归函数生成二叉树

c - C中使用递归的回文数

python - 如何去掉某个字符串后的所有内容

python - 我在 python 中的 speech.listen(source) 正在停滞

javascript - JavaScript 中的递归出现错误

python - 如何从softmax层中提取权重?

Python获取mac剪贴板内容

python - 使用 Python 和 py-postgresql 返回的查询中的空格