I want to have the program check if the code is or is not 'w', 'W', 'd' or 'D' and then direct the user from there, but as it is, it always goes to invalid() even when the input is 'w', 'W', 'd' or 'D'. And I don't want to use 'while code is equal to 'w', 'W', 'd' or 'D' continue on' because even though that works while the program is running, it causes the program to start over from the beginning after it's finished.
Plus, I'm not allowed to do the simple way using if statements
if code == 'W' or code == 'w' or code == 'D' or code == 'd':
prevbalance = float(input('Enter your previous balance: $'))
else:
invalid()
Here is the problem area:
code = input('Enter your transaction code: ')
while not code == 'W' or code == 'w' or code == 'D' or code == 'd':
invalid()
prevbalance = float(input('Enter your previous balance: $'))
Here is the entire program if it helps:
def invalid():
input('Invalid transaction code. Please select another code.')
main()
def deposit(prevbalance, amount, code):
Wbalance = ''
Dbalance = prevbalance + amount
balance(Wbalance, Dbalance, code)
def withdrawal(prevbalance, amount, code):
Dbalance = ''
Wbalance = prevbalance - amount
if amount > prevbalance:
print('~~ERROR~~ You cannot withdrawal more than you have')
input(' Please try a lower amount back at the main menu')
main()
else:
balance(Wbalance, Dbalance, code)
def balance(Wbalance, Dbalance, code):
if code == "W" or code == "w":
print('Your new balance is: $',format(Wbalance, ',.2f'),)
else:
print('Your new balance is: $',format(Dbalance, ',.2f'),)
def main():
name = input('Enter your name: ')
ID = input('Enter your account ID: ')
code = input('Enter your transaction code: ')
while not code == 'W' or code == 'w' or code == 'D' or code == 'd':
invalid()
prevbalance = float(input('Enter your previous balance: $'))
amount = float(input('Enter your transaction amount: $'))
if code == "W" or code == "w":
withdrawal(prevbalance, amount, code)
elif code == "D" or code == "d":
deposit(prevbalance, amount, code)
main()
input('Press ENTER to continue...')