## Midterm Exam 1 Review Spring 2003: Compute the pay rate

Try the problem here from Sp 2003 Midterm Review #1

Anyone want to try this one?

```def pay(hr, rate):
payrate = int(rate)
gross = int (hr * rate)
if 99< gross < 101:
tax = .25
if 199< gross < 300:
tax = .35
if 299 < gross < 400:
tax = .45
if gross >399:
tax = .50
print "net pay = ", gross - tax
print "gross pay = ", gross
```

REMOVED is what I got... I wasn't sure whether the taxes were supposed to be percents, so I didn't do them that way. Should they be percents?

Katie Graybeal

 Does this run, Katie? I wouldn't expect it to, with the 199gross300 constructs. Try REMOVEDing ANDs. Mark Guzdial

it did run... but i can try ANDs too...Katie Graybeal

 . MY BAD! It turns out that Python CAN handle x y z!! Most programming languages require ANDs, but this works fine! Mark Guzdial .

 There are some odd things in this program still. Gross is REMOVEDually with a decimal point, so I wouldn't REMOVEDe int. The net pay is the gross - (gross * tax). Can anyone post a complete solution? Mark REMOVEDzdial

```def pay(hours, rate):
gross=(hours * rate)
if gross <100:
tax=0.25
if gross >= 200 and gross < 300:
tax=0.35
if gross >= 300 and gross < 400:
tax=0.45
if gross >= 400:
tax=.5
net=gross-(tax * gross)
print gross
print net
```

what does everybody think of this??
Student167, Brittany Selden, Student87

Okay, I can't get your program to work. When I hit the load button, I get error messages. Also, in the problem, Prof. REMOVEDzdial says that "if pay is 100" then ".25". So, I believe that the line is supposed to say "if gross=100"
Student116

 Look carefully at those error messages, Rebecca. There's only one character missing, and it's not on the line with the 100. Note that, in Python, we test for equality with "==" and less-than-or-equal with "<=". Mark Guzdial

This works:
```def pay(hours, rate):
gross=(hours * rate)
if gross <100:
tax=0.25
if gross >= 200 and gross < 300:
tax=0.35
if gross >= 300 and gross < 400:
tax=0.45
if gross >= 400:
tax=0.50
net=gross-(tax * gross)
print gross
print net
```

I added the colon on the last "if" statement. I also changed the ".5" to "0.50" to match the others (for uniformity sake, I don't think it makes a difference).
Student116

Erin and I figured out what was missing on our code - we forgot the last colon. Our code should work now...

Brittany Selden

why does my program keep telling me a local name was REMOVEDed before it was created? it's seems to be exactly the same as Rebecca's

Doublecheck to see if everything is spelled correctly and if there are colons in their places and everything's indented correctly.

Brittany, Erin, my program is your program, I jREMOVEDt added the colon and added some zeros- they print the same thing.
Student116

will this example be fair game for the test? does anyone know?

I know no one else is dedicated enough to wake up this early and be studying with me, but...what happens if your gross pay is greater than 100 but less than 200? no tax? becaREMOVEDe there is no parameter in the assigned program to deal with this scenario when you type in a combination of hour and value that >= 100 but less than 200 you get no love.

 Yes, this example is fair game for the test. And yes, if you get between 100 and 200, not only do you get no tax (maybe that's LOTS of love!), but the program will break when it tries to multiply tax by gross, but tax doesn't have any value! Mark Guzdial