-3

我试图弄清楚从这里去哪里,我知道我必须在某个地方有一个累加器来显示用户的当前余额。我不太确定如何实现它,以及当用户想要做其他事情比如“退出”和其他事情时保持它的持久性。

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

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

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

1 回答 1

0

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

你想要一个程序,当用户没有点击 5 时不会退出,对吗?

我会这样做的方式

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

但是,这并不能确保“新客户必须开设一个新帐户才能正常继续”。这并不重要。但如果你必须。然后在while之前执行选项1

于 2016-06-25T01:28:53.600 回答