如何更新变量

时间:2019-06-17 19:43:30

标签: python-3.x

当用户将现金存入银行时,当我被问及是否要再次存入时,我希望能够更新现金变量。

cash = 1200
Bank_balance = 0
def Deposit():
    try:
        Deposit1 = float(input(f"You have ${cash}. How much do you want to 
deposit?\n>>>"))
        if Deposit1 <= cash:
            bank_bal = Bank_balance + Deposit1
            cash = cash - Deposit1

            print(f"{user}, your bank balance is: ${bank_bal}, and your 
cash is: ${cash}\n")
            ask = input(f"Do you want to make another deposit? 
(y/n)\n>>>").lower().strip()
            if ask == "y":
                print("Ok!")
                Deposit()
            else:
                print("Going back to menu!")
                mainmenu()


        elif Deposit1 > cash:
            print("Insufficient Funds. Try again!")
            Deposit()

    except ValueError:
        print("Input a number!")
        Deposit()

0 个答案:

没有答案