In: Computer Science
i'm working on this assignment where we must simulate a bank account. I am having a few issues. The first issue is that for menu option 1 i am struggling to make the program so that I can add the name and balance of the account all at once. For example I would type "mike 350" and it would update the dictionary with a new account and balance, right now i have to open the account then deposit a balance separately using two different menu functions. The second issue i am having is that every account name in the dictionary has the same balance, I need to have each person have a separate balance. The third and last issue I am having is with menu option #6, i am not sure how to list the account names and balances with a number of each account to the left, the professor wants the output to look like this for option 6
No Customer Name Balance
== ============= =======
1 joe 10
2 jim 20
3 eric 30
I have made it this far.
def main():
print("1. Open an account")
print("2. Close an Account")
print("3. Deposit money")
print("4. Withdrawal money")
print("5. Enquire about balance")
print("6. Print a list of customers and balances")
print("7. Quit")
accounts = {}
balance = 0
main()
while True:
menu_choice = int(input("Type in a menu choice: "))
#menu choice 1
if menu_choice == 1:
number = input("Enter name of the new customer and \nthe amount of
money to be deposited \n into the new account (Ex. 'Mike
350'):")
if number in accounts:
print('This customer already exists!')
else:
accounts[number]=balance
print ("Account name", number, "opened.")
#menu choice 2
elif menu_choice == 2:
number = input("Account name:")
if number not in accounts:
print('Enter the customer/account name to be deleted: ')
if number in accounts:
if balance>0:
print('Can not close an account with balance greater than
zero')
else:
del accounts[number]
print ("Account number", number, "is closed.")
#menu choice 3
elif menu_choice == 3:
print ("Enter the customer name for deposit: ")
number = input("Account name: ")
if number in accounts:
deposit = float(input("Enter the amount to be deposited: "))
balance += deposit
print ("your balance is:", balance-deposit, "before deposit")
print ("Your balance is:", balance, "after deposit")
else:
print ("This customer doesn't exist!")
#menu choice 4
elif menu_choice == 4:
number = input("Enter the customer name for withdrawl: ")
if number not in accounts:
print('This customer doesnt exist!')
if number in accounts:
withdraw = float(input("Enter the amount to be withdrawn: "))
if withdraw <=balance:
balance -=withdraw
print ('your balance is:', balance+withdraw, 'before
withdrawal')
print ("Your balance is:", balance, 'after withdrawal')
if withdraw >balance:
print ('your balance is:', balance, 'before withdrawal')
print ('You dont have enough balance to cover the withdrawal')
#menu choice 5
elif menu_choice == 5:
number = input('Enter the customer name for balance enquiry:
')
if number not in accounts:
print('This customer doesnt exist!')
if number in accounts:
print('your balance is:', balance)
#menu choice 6
elif menu_choice == 6:
print ("Accounts")
for x in accounts.keys():
print ('No Customer Name Balance')
print ('============================')
print (x , balance\n)
#menu choice 7
elif menu_choice == 7:
print ("Quit.")
break
else:
print ("Please enter a menu choice between 1 and 6.")
main()