Мой учитель назначил банковскую программу для банкоматов, которую мы должны создать, используя ряд функций, и нам не разрешено использовать глобальные переменные для этого.Единственная проблема в том, что я не могу понять, как передавать переменные, чтобы иметь обновленный баланс.
Когда я запускаю программу, она работает просто отлично, за исключением того, что когда она печатает весы, она печатает все, что только что было внесено или снято.
balance = 0.0
# welcome the user to the program
def welcome():
print("Welcome to the ATM program!\nThis program allows you to deposit, withdraw, or view your balance!")
def goodbye():
print("Thank-you for using the ATM!")
def main():
# print options menu
def menu():
userChoice = 0
while userChoice != 4:
print("1...Deposit\n2...Withdraw\n3...View Balance\n4...Quit")
userChoice = int(input("Please enter your choice now: "))
# deposit function
def deposit(balance):
print("\n1...Deposit\n")
deposit = float(input("Please enter the amount you would like to deposit: "))
# update balance
balance = balance + deposit
print("Your balance is now $"+str(balance)+".")
return balance
# withdraw function
def withdraw(balance):
print("\n2...Withdraw\n")
withdraw = float(input("Please enter the amount you would like to withdraw: "))
# update balance
balance = balance - withdraw
print("Your balance is now $"+str(balance)+".")
return balance, withdraw
def viewBalance(balance):
print("\n3...View Balance\n")
print("Your balance is", balance)
if userChoice == 1:
print(deposit(balance))
elif userChoice == 2:
withdraw(balance = 0.0)
elif userChoice == 3:
viewBalance(balance)
else:
return
menu()
welcome()
main()
goodbye()