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 PageUploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Fall 2006 Midterm 1 Review: Compute the pay rate

Questions?


def Pay(hours, pay):
  if(hours*pay < 100):
    print"gross pay"    
    print(hours*pay) 
    print "tax"    
    print(.25*hours*pay)
    print "net pay"    
    print(hours*pay - .25*hours*pay)
  if(hours*pay >= 100 and hours*pay <200):
    print"gross pay"     
    print(hours*pay) 
    print "tax"     
    print(.25*hours*pay) 
    print "net pay"    
    print(hours*pay - .30*hours*pay)
  if(hours*pay >= 200 and hours*pay <300):
    print"gross pay"     
    print(hours*pay) 
    print "tax"     
    print(.25*hours*pay)    
    print "net pay"    
    print(hours*pay - .35*hours*pay)
  if(hours*pay >= 300 and hours*pay <400):
    print"gross pay"     
    print(hours*pay)
    print "tax"     
    print(.25*hours*pay) 
    print "net pay"    
    print(hours*pay - .45*hours*pay)
  if(hours*pay > 400):
    print"gross pay"     
    print(hours*pay) 
    print "tax"     
    print(.25*hours*pay)   
    print "net pay"    
    print(hours*pay - .50*hours*pay)


A bit long but I think it gets the job done.
Ok. Can anyone write this more succinctly? Colin Potts



def pay(hoursWorked, hourlyRate):

  grossPay = hoursWorked*hourlyRate

  if grossPay < 100:
    taxRate = .25
  if 200 > grossPay >= 100:    
    taxRate = .3
  if 300 > grossPay >= 200:
    taxRate = .35
  if 400 > grossPay >= 300:
    taxRate = .45
  if grossPay > 400:
    taxRate = .5 

  taxedAmount = taxRate*grossPay

  netPay = grossPay - taxedAmount

  print grossPay
  print netPay


Maybe like this? I may be over looking something. Is the above code correct?

Thanks
Megan Bowen


def pay(h, r):
  pay = h * r
  if(pay < 100):
    finalpay = pay - (pay * .25)
  if(pay >= 100 < 200):
    finalpay = pay - (pay * .30)
  if(pay >= 200 < 300):
    finalpay = pay - (pay * .35)
  if(pay >= 300 < 400):
    finalpay = pay - (pay * .45)
  if(pay >= 400):
    finalpay = pay - (pay * .50)
  print "gross pay =", pay
  print "net pay =", finalpay



def pay(hoursWorked, hourlyRate):
  grossPay = hoursWorked*hourlyRate
    
  if (grossPay  100):
      tax=.25*grossPay
    
  if (grossPay >=100 and grossPay <200):
      tax=.30*grossPay
      
  if (grossPay >=200 and grossPay 300):
      tax=.35*grossPay
    
  if (grossPay >=300 and grossPay <400):
      tax=.45*grossPay
     
  if (grossPay >=400):
      tax=.5*grossPay
      
  netPay=grossPay-tax
  print "gross= $", grossPay
  print "net= $", netPay 

Leah McClellan

def pay(hoursworked, hourlyrate):
  grosspay = hoursworked * hourlyrate
  if grosspay < 100:
    tax = .25
  if grosspay >= 100 and pay < 200:
    tax = .3
  if grosspay >= 200 and pay < 300:
    tax = .35
  if grosspay >= 300 and pay < 400:
    tax = .45
  if grosspay >= 400:
    tax = .5
  print tax * grosspay
  print grosspay - tax

I wrote it in JES and worked on my first try! I'm so proud of myself :D. Let me know if I should punish myself for potentially messing up...
Brittany Walsh

def pay (hours, rate):
  grossPay = hours*rate
   
  if grossPay < 100:
    netPay = grossPay – (grossPay*.25)

  if grossPay >= 100 and grossPay < 200:
    netPay = grossPay – (grossPay*.30)

  if grossPay >= 200 and grossPay < 300:
    netPay = grossPay – (grossPay*.35)

  if grossPay >= 300 and grossPay < 400:
    netPay = grossPay – (grossPay*.45)

  if grossPay >= 400:
    netPay = grossPay – (grossPay*.50)

  print grossPay
  print netPay


Is the statement "Compute the taxed amount as tax rate gross pay" just telling us how to compute taxed amount or is it telling us that it should be defined somewhere in our function
i.e.
if grossPay  400:
    taxRate = .5 

  taxedAmount = taxRate*grossPay


My function doesn't define taxedAmount but it generates the same ouput as the functions that do; could I still have points taken off?

Brittany, don't forget to use "grosspay" on both sides of "and" : if grosspay >= 100 and grosspay 200:



Link to this Page