I have this code to calculate tax. I am having an syntax error like this NameError: name 'raw_input' is not defined
and don't know why? I am quite new to coding and have little understanding about the subject. Like it takes me forever to write few lines and understand what is what after some long research.
I wrote something and it gives me an error, and I am not really sure about my error. Like I did something similar after an agonizing time later, and float()
did the trick with it. Not sure what I am missing?
P.S: I read the how to upload the code properly for people to approach it, like minimal version. I don't think I quite grasped what it wants me to do. Sorry if that is violated a rule or made it harder to read!
# input of tax status
tax_status = raw_input('Enter your tax status(single or married) : ')
# validate tax status
while tax_status.strip().lower() != 'single' and tax_status.strip().lower() != 'married':
print('Invalid value. Tax status can be eiher single or married')
tax_status = raw_input('Enter your tax status(single or married) : ')
#input of income
income = float(raw_input('Enter your income: '))
# validate income > 0
while income <= 0 :
print('Invalid value. Income must be greater than 0')
income = float(raw_input('Enter your income: '))
tax_amount = 0
# calculate tax amount based on tax_status and income
if tax_status == 'single':
if income <= 9700:
tax_amount = (10*income)/100
elif income <= 39475:
tax_amount = (12*income)/100
elif income <= 84200:
tax_amount = (22*income)/100
elif income <=160725:
tax_amount = (24*income)/100
elif income <= 204100:
tax_amount = (32*income)/100
elif income <= 510300:
tax_amount = (35*income)/100
else:
tax_amount = (37*income)/100
else:
if income <= 19400:
tax_amount = (10*income)/100
elif income <= 78950:
tax_amount = (12*income)/100
elif income <= 168400:
tax_amount = (22*income)/100
elif income <=321450:
tax_amount = (24*income)/100
elif income <= 408200:
tax_amount = (32*income)/100
elif income <= 612350:
tax_amount = (35*income)/100
else:
tax_amount = (37*income)/100
# output the tax amount
print('Your tax amount is $%.2f' %(tax_amount))
I at least want to know what I did wrong, and how can I figure out to make it run? Like what I missed that it causes me this issue, that when I try to run it doesn't?