I am writing code that simulates a bank application for just one customer. I got it all down, but the problem is that if the user doesn't input D
W
B
or E
then it is supposed to say Invalid Choice. Try again.
But it prints this even after I put in the deposit amount and everything is fine. So my question is on how to make Invalid Choice. Try again
print only if the user inputs something other than D
W
B
or E
and not after inputting a number?
Here's my code:
response = "D"
balance = 0
deposit = 0
withdraw = 0
while (response=="D") or(response=="W") or (response=="B"):
print("Type D to deposit money")
print("Type W to withdraw money")
print("Type B to display Balance")
print("Type E to exit")
ask = input("Enter your choice now: ")
if(ask=="D"):
deposit = int(input("Please enter your amount to deposit: "))
balance = float(balance + deposit)
if(ask=="W"):
withdraw = int(input("Please enter the amount you want to withdraw: "))
balance = float(balance - withdraw)
if(balance<withdraw):
print("Not enough balance")
if(ask=="B"):
print("Your balance is: " +str(balance))
if(ask=="E"):
break
else:
print("Invalid Choice. Try again")
print("*****")