I get an invalid syntax error when I try to subtract an input variable from another variable, despite the syntax being completely valid. I’ve tried to use different named variables. Here is my code:
init_bal = 1000.00
bal = init_bal
name = raw_input("What is the name on your account?: ")
invalid = False
transact = True
print "Hello,", name+"!"
def banking():
global transact
while transact == True:
global transact
global invalid
global bal
global name
print "Your balance is $"+str(round(bal, 2))
type = raw_input("Are you making a deposit or withdrawal?: ")
if type == "deposit" or "Deposit" or "DEPOSIT" or "D" or "d":
global bal
deposit = float(input("How much would you like to deposit?: $"))
bal += deposit
print "Your new balance is $"+str(round(bal, 2))
invalid = False
elif type == "withdrawal" or type == "Withdrawal" or type == "WITHDRAWAL" or type == "W" or type == "w" or type == "Withdraw" or type == "withdraw":
global bal
#replaced bal with test to see if it was the variable name
test = 5000
#user inputs how much they want to withdraw
withdrawal = float(input("How much would you like to withdraw?: $")
#stupid sh*t that doesn't want to work
bal -= withdrawal
#checks if balance is negative. If so, change the text that asks you to do another transaction, and revert the change
if bal < 0:
bal += withdrawal
print "You cannot withdraw more than your balance!"
invalid = True
else:
print "Your new balance is $"+str(round(bal, 2))
invalid = False
else:
print "Invalid transaction!"
invalid = True
#asks the user if they want to do another transaction
def again():
if invalid == True:
again = raw_input("Would you like to try again? Enter Y or N: ")
if again = "Y" or "y":
transact = True
elif again = "N" or "n":
transact = False
print "Thank you", name, "for putting your trust in us."
else:
print "Please enter Y or N!"
again()
else:
again = raw_input("Would you like to make another transaction? Enter Y or N: ")
if again = "Y" or "y":
transact = True
elif again = "N" or "n":
transact = False
print "Thank you", name, "for putting your trust in us."
else:
print "Please enter Y or N!"
again()
again()
banking()
(I have Python 2.7, so the issue could be that it’s outdated)
EDIT: Thank you everybody!