I need help with this program in Python. Write a program called BankApp to simul
ID: 3771866 • Letter: I
Question
I need help with this program in Python. Write a program called BankApp to simulate a banking application. Create a list of 3 users called "Customers" [Mike, Jane, Steve] Create a list of Balances [300, 300, 300] corresponding to the initial balances for each customer. When a user runs your program, it should ask for the users name first. Check if the name matches a customer in the list. Store the index number of this customer in a variable. Use this variable to reference the correct balance in the balance list later in the program. After asking for the user name, display a menu with the following options and ask the user for input (Use a While Loop). Type D to deposit money Type W to withdraw money Type B to display Balance Type C to change user, display user name Type E to exit • If the user types D (Deposit Function) Ask the user to enter the amount to deposit. Then call the Deposit Function, passing the deposit amount as a parameter. The function should update the Balance. Then display the new balance (this should not happen in the function). Then display the menu again • If the user types W then (Withdraw Function) Ask the user to enter the amount he/she wants to withdraw. Before calling the withdraw function, make sure there is enough balance. Call the Balance function before Withdraw function!! Then call the Withdraw Function, passing the withdraw amount as a parameter. The function should update the Balance. Display the new balance to the user (this should not happen in the function). Then display the menu again • If the user enters B, then Display the Balance. • If the user enters C then Ask for the user name and change the index number variable to match. • If the user types E. then Terminate the program. • If the user types any other option: PS: You program must keep displaying the menu until the user types the option E, to exit the program.
Explanation / Answer
customers = ["Mike", "Jane", "Steve"]
balance = [300, 300, 300]
def Balance( i ):
return balance[i]
def Deposit(i, amt):
balance[i] = balance[i] + amt
print "new balance = "+str(Balance(i))
return
def Withdraw(i, amt):
balance[i] = balance[i] - amt
print "new balance = "+str(Balance(i))
return
i=0
while True:
name = raw_input("enter the name of customer ")
if name in customers:
i = customers.index(name)
break;
while True:
print "enter 'D' to Deposit"
print "enter 'W' to withdrawn money"
print "enter 'B' to display balance"
print "enter 'C' to change the customer"
print "enter 'E' to exit"
sel = raw_input("enter your choice ")
if(sel =="b" or sel =="B"):
print "the currunt balance = "+str(Balance(i))
elif sel=="d" or sel=="D":
amt = float(raw_input("enter amount to be deposited "))
Deposit(i,amt)
elif sel=="w" or sel=="W":
amt = float(raw_input("enter the amount to be withdrawn "))
bal = Balance(i)
if amt > bal:
print "Insufficient balance to withdraw "+str(amt)+" , currunt balance is "+str(bal)
else:
Withdraw(i,amt)
elif sel == "c" or sel == "C":
while True:
name = raw_input("enter the name of customer ")
if name in customers:
i = customers.index(name)
break;
else:
print "enter a valid customer name"
elif sel=="e" or sel=="E":
break;
else:
print "enter a valid option"
output:
E