Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 递归存取_Python_Recursion - Fatal编程技术网

Python 递归存取

Python 递归存取,python,recursion,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 =

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

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()
def递归(n):
打印(“您有美元”,n,“在银行里!”)
选项=(输入(“您想取款还是存款?”)
如果选项==“撤回”或“撤回”:
draw=int(输入(“您想从您的帐户中提取多少?”)
递归(n-撤回)
elif选项==“存款”或“存款”:
存款=int(输入(“您想存多少?”)
递归(n+存款)
其他:
打印(“不是有效选项!”)
打印(“正在关闭!”)
def货币(n):
如果n<0:
打印(“你没钱了!”)
def main():
递归(100)
main()
请让我知道我的错误在这里

您应该更改:

if option == "withdraw" or "Withdraw":
致:


对存款也要这样做。

@QPaysTaxes它只允许我做取款部分,即使我为将来输入存款,你也需要将所有相关信息输入问题本身。当它出现在评论中时并不太糟糕,但是当它全部出现在一个地方时会更整洁。
if option == "withdraw" or option == "Withdraw":