递归存取

2024-04-25 23:05:25 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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()

请让我知道我的错误在这里!你知道吗


Tags: ortoyouinputifdefhowint
1条回答
网友
1楼 · 发布于 2024-04-25 23:05:25

您应该更改:

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

收件人:

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

deposit也是这样。你知道吗

相关问题 更多 >

    热门问题