我必须创建一个基本的银行菜单,但我一直很难理解它

I have to create a basic Bank Menu and I've been having a hard time wrapping my head around it

我想知道从这里到哪里去,我知道我必须在某处有一个累加器来显示用户的当前余额。我不太确定如何实现它,以及在用户想要执行其他操作(例如 'withdrawal' 和其他操作)时保持它的持久性。

我也试过以某种方式让程序自行终止,但也很难搞清楚。我什至尝试过休息一下,然后再次查看它,看看我是否能想出一些新的东西。不太确定还能做什么。

编辑:我可以看出我一直在混淆一些人。这就是我被要求做的:我被要求创建一个显示银行账户菜单的基本程序,其中每个选项都会做这些事情:开立账户会问候新用户并让他们选择进行初始存款以创建帐户。存款只会更新帐户的余额。 Withdraw 将通过提取用户要求从余额中取出的金额来更新帐户。 Balance 只会显示用户的余额,exit 会退出程序

balance = 0.0000


print("Welcome to Sys Financial Bank!  New clients must open a new account to continue properly.")

print("""1) New Account
2) Deposit
3) Withdraw
4) Balance
5) Exit""")
option = int(input("Please input the number corresponding with the option in the menu: "))

if option == 1:
    option_1 = float(input("Input initial deposit amount to create account: $"))
    balance =+ option_1

elif option == 2:
    option_2 = float(input("Input deposit amount: $"))
    balance = option_1 + option_2

elif option == 3:
    option_3 = float(input("Input withdrawal amount: $"))
    balance = option_1 - option_3

elif option == 4:
    print("Your current balance is: ", balance)

else:
    import sys
    sys.exit()

我不明白你想做什么,但我猜。

您想要一个程序,当用户不按五时不退出,对吗?

我的做法

from sys import exit
balance = 0.0000
print("Welcome to Sys Financial Bank!  New clients must open a new account to continue properly.")
print("""1 New Account \n2) Deposit \n3) Withdraw \n4) Balance \n5) Exit""")
try:
    while True:
        option = int(input("Please input the number corresponding with the option in the menu: "))
        if option == 1:
            option_1 = float(input("Input initial deposit amount to create account: $"))
            balance += option_1
        elif option == 2:
            option_2 = float(input("Input deposit amount: $"))
            balance += option_2

        elif option == 3:
            option_3 = float(input("Input withdrawal amount: $"))
            balance -= option_3

        elif option == 4:
            print("Your current balance is: ", balance)

        elif option == 5:
            exit('Have a nice day')
except ValueError:
    print('Input a number')

然而这并不能确保"New clients must open a new account to continue properly"。这并不重要。但如果你必须的话。然后在 while

之前执行选项 1