Change Contents of the Bubble
Welcome to CS1315. Click on the python to add comments.

Looking for the book? They have it at the Engineer's Bookstore at 748 Marietta St NW. Here is there website: http://www.engrbookstore.com/ - Monica

Hotspots: Slides and CodeTA CornerComments?AnnouncementsFAQStatic Webspace
View this PageEdit this Page (locked)Uploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Midterm Exam 1 Review Fall 2003: Compute the pay rate

(Back to Fall2003 Midterm Review 1)

Answers? Comments? Comments on answers?


def pay(hours, rate):
gross = hours rate
if gross 100:
tax = .25
if gross >=200 and gross 300:
tax = .35
if gross =300 and gross 400:
tax = .45
if gross = 400:
tax = .50
taxtopay = gross * tax
net = gross - taxtopay
print "Gross pay is" gross "but net is only" net

 def pay(hours, rate):
  gross = hours rate
  if gross  100:
   tax = .25
  if gross >=200 and gross 300:
    tax = .35
  if gross >=300 and gross 400:
    tax = .45
  if gross >= 400:
    tax = .50
  taxtopay = gross * tax
  net = gross - taxtopay
  print "Gross pay is" gross "but net is only" net

Prints need commas between things to print. Mark Guzdial


Are you multiplying hours times rate? How do you tell the program to specifically do that? Kelly Farrell

I think the program got messed up because certain symbols require special combinations like *

Yeah, the asterisks got left out.

See the FAQ page on how to type code into the CoWeb. Mark Guzdial


this is what i got:
def pay(hrs, rate):
     grosspay = (hrs * rate)
     if grosspay < 100:
          tax=0.25
     if grosspay >= 200 and grosspay < 300:
          tax=0.35
     if grosspay >= 300 and grosspay < 400:
          tax=0.45
     if grosspay >= 400:
          tax=0.50
     netpay=grosspay-(tax * grosspay)
     print grosspay
     print netpay



Looks good to me! Kelly Farrell

This is my function. I loaded it into Jes and have tried out some numbers. It works for most all, but when I tried pay(18,7), I got the following error: A local name was used before it was created. You need to define the method or variable before you try to use it.
Please check line 17 of C:\JES\pay.py
Why?!?
def pay(hours,ratebyhour):
  grosspay = (hours*ratebyhour)
  print "The gross pay is", grosspay

  if (grosspay < 100):
    taxrate = 0.25

  if (grosspay >= 200) and (grosspay < 300):
    taxrate = 0.35

  if (grosspay >= 300) and (grosspay < 400):
    taxrate = 0.45

  if (grosspay >= 400):
    taxrate = 0.50

  taxedamount = (grosspay*taxrate)
  netpay = grosspay - taxedamount
  print "The net pay is", netpay

Yeah, that problem is not you as long as what you have in JES is EXACTLY what is above. If so it is a glitch with JES, because it works perfectly for me. Try saving your recipe, then shut down JES. Then try to open JES and then open the recipe again. That should work. But don't worry. Even if JES doesn't know it, your program works fine. Lauren Biddle


IF the grosspay is between 100 and 200 in this program, then the taxrate gets no value, so you get an error when you go to compute the taxedamount because taxrate is undefined. Mark Guzdial



Link to this Page