This is more a plea for help from the ubuntu community. I've done a lot of searches and reading and I guess I'm missing something. I'm trying to write a very basic program in python, here's the issue: I ask the question raw_input("question" )
, then assign an if
statement like so: This is the error:
The debugged program raised the exception unhandled NameError
"name 'tx_rate' is not defined"
File: /home/Budget.py, Line: 47.
This is the code:
ans1 = raw_input("Do you know your tax rate?" )
if 'ans1' == 'yes':
tx_rate = raw_input("What is it?")
float(tx_rate)
tx_rate = float(tx_rate)
print "Thank you! Will use tax rate %s, instead of 0.15!" % (tx_rate)
elif "ans1" == "no":
print "Okay, that's alright, we'll use 0.15 as the average tax rate!"
tx_rate = 0.15
else:
print "Sorry, incorrect value, please answer yes or no."
gross_pay = (hrs * rate) * 4.0
net_pay = gross_pay - (gross_pay * tx_rate) [That last line is line 47]
The error comes from the variable for tx_rate never being assigned because weather I asnwer yes or no it runs the ELSE option
So basically it asks me "Do you know your tax rate?" and no matter what I enter it takes me to the else option and displays the error. Which tells me I need to loop it back, how would I do that? So that when "else" is called, make it rerun the question, until if or elif are satisfied?
Aucun commentaire:
Enregistrer un commentaire