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) * 4.0 [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 what happens is that when I run the code, I get through a lot of questions, were I ask about earnings, and then when it loads that question up there, I answer yes or no and it prints the else option and then tells me
error "name 'variable' is not defined] seemingly because, since it won't allow me to answer with yes or no it just tries to run code with a non existent variable. Could anyone help me fix this? Sorry if this isn't where I should ask!