So today is literally my first day of learning a programming language so I'm very new to Python. I'm taking the online Python for Informatics course at the University of Michigan and our first real assignment is to create a simple gross pay rate calculator.
That was simple enough so I decided I wanted to expand what the program could do to calculate net pay and account for taxes. The trouble I'm having is determining how I can dynamically (if that's even the right word) set the value of the variable "taxrate" based on a series of conditional statements.
I have yet to find the answer in searching through Python's site and Stack Overflow. I think my limited understanding of programming probably is limiting my ability to interpret properly what I have found.
Just looking for a little help:
Code:
#This program is intended to calculate the net pay of employees
#This first section includes a loop for mistakes and finds gross pay
while True:
hours = raw_input('How many hours do you work weekly?')
hours1 = float(hours)
rate = raw_input('What is your hourly rate of pay?')
rate1 = float(rate)
grosspay = hours1 * rate1
taxstatus = raw_input('Do you pay taxes?')
#This secdtion is establishing the tax bracket the user falls into
taxbracket = taxrate
if grosspay <= 1000:
taxrate = 0.90
if grosspay > range(1000,1500):
taxrate = 0.78
if grosspay >= 1501:
taxrate = 0.63
# This section is intended to calculate pay after taxes
grosspay = hours1 * rate1
if taxstatus == 'yes':
netpay = grosspay * taxrate
print'Your weekly pay after taxes is',netpay
if not taxstatus:
print grosspay
When I run this in PyCharm it lets me know that "taxrate" hasn't been defined. I ultimately want the program to set the "taxrate" based on what the users "grosspay" is. Is what I'm trying to do possible? I'm assuming it is and that I just don't understand how to do it.
Any help is greatly appreciated and in case someone is wondering what the loop is for I've got a user error checker that I'm working on after this portion of the program completes.
taxbracket = taxrateget rid of this line, since you're not usingtaxbracketanywheretaxbracket = taxrateis where your problem is, since you haven't yet definedtaxrate. But you never usetaxbracketeither, so you can delete that line entirely. Second, you'll need to changeif grosspay > range(1000,1500):toif grosspay <= 1500: