Still a beginner with Python. 7 Weeks into an 8 week course. My assignment was to polish my previous assignment. What I'm trying to add is not required, but I think it would be good practice to always aim for the best UI possible. I currently have a functional ATM script that works fine, once, then it must be restarted to use one of the other functions. What I want to do is somehow call the user_options dictionary I created to prompt the user to see if they want to perform another task while the ATM program is still running.
To clarify, I would like the program to be able to start, prompt the user, run the function the user selects, then loop back out to the prompt for another input.
If I change the user_options dict to a function, I don't know how to do it. Sorry for rambling, anyway, here is my code:
import sys
account_balance = float(500.25)
# defines theprintbalance function
def balance():
print("Your current balance:\n" + str(account_balance))
#defines the deposit function
def deposit():
global account_balance
#input paramaters for deposit
deposit_amount = input("How much would you like to deposit today?\n")
#modifies account balance with deposit ammount
account_balance += float(deposit_amount)
#prints the deposit amount and current blanace
print("Deposit was $" + str('%.2f' % float(deposit_amount)) + ", current
balance is $" + str(account_balance))
#defines withdrawal function
def withdrawal():
global account_balance
#input paramaters for withdrawal
withdrawal_amount = input("How much would you like to withdraw today?\n")
#if statement for withdrawal amount that exceeds balance
if float(withdrawal_amount) > account_balance:
print("$" + str('%.2f' % float(withdrawal_amount)) + " is greater than
your account balance of $" + str('%.2f' % float(account_balance)))
#restarts the withdrawl
print('Please enter an amount less than or equal to your current balance
for withdrawal')
withdrawal()
#else statement for successful withdrawal
else:
account_balance -= float(withdrawal_amount)
print("Withdrawal amount was $" + str('%.2f' % float(withdrawal_amount))
+ ", current balance is $" + str('%.2f' % float(account_balance)))
#defines quit function
def quit():
#prints quit message
print("Thank you for banking with us.")
#creates user input dict and removes previously used if/else loop
user_options = input("What would you like to do? (B)alance, (W)ithdrawal,
(D)eposit, (Q)uit\n")
options = {'B': balance,
'b': balance,
'W': withdrawal,
'w': withdrawal,
'D': deposit,
'd': deposit,
'Q': quit,
'q': quit,
}
options[user_options]()
If anyone has ideas or suggestions, that'd be great. This is PURELY a cosmetic thing that I want to add to the program. I don't think I'll be graded any differently on it. I just want to learn.