* using python 3 functions and list- I can\'t seem it get it to run properly whe
ID: 3857298 • Letter: #
Question
* using python 3 functions and list- I can't seem it get it to run properly where I can get the balance, deposit and withdraw amount to come out properly it keeps showing [300, 300, 300] *
You are going to 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.
thanks in advance
Explanation / Answer
def updateBalance( amount,index,list ):
list[index] += amount
def withdrawBalance( amount,index,list ):
list[index] -= amount
Customers = ["Mike", "Jane", "Steve"]
Balances = [300, 300, 300]
name = input("Enter user name ")
index = Customers.index(name)
if name in Customers:
while True:
print ("Type D to deposit money")
print ("Type W to withdraw money")
print ("Type B to display Balance")
print ("Type C to change user, display user name")
print ("Type E to exit")
inp = input()
if inp == "D":
amount = int(input("Enter the amount to deposit: "))
updateBalance(amount,index,Balances)
print ("New balance %d" % Balances[index])
elif inp == "W":
print ("Current balance is %d" % Balances[index])
amount = int(input("Enter the amount to withdraw: "))
if amount <= Balances[index]:
withdrawBalance(amount,index,Balances)
print ("New balance %d" % Balances[index])
elif inp == "B":
print ("Current balance is%d" % Balances[index])
elif inp == "C":
name = input("Enter new user name ")
Customers[index] = name
elif inp == "E":
break
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.