{{ message }}

Instantly share code, notes, and snippets.

# ZeroRaven/4.6.py

Created Mar 29, 2019
4.6 Write a program to prompt the user for hours and rate per hour using input to compute gross pay. Pay should be the normal rate for hours up to 40 and time-and-a-half for the hourly rate for all hours worked above 40 hours. Put the logic to do the computation of pay in a function called computepay() and use the function to do the computation…
 def computepay(h,r): if h > 40: p = 1.5 * r * (h - 40) + (40 *r) else: p = h * r return p hrs = input("Enter Hours:") hr = float(hrs) rphrs = input("Enter rate per hour:") rphr = float(rphrs) p = computepay(hr,rphr) print(p)

### saydiburkhon commented Apr 8, 2020

 1.5 * r * (h - 40) + (40 *r) from computation , I get different figures , could you please explain how come it gives the 498.75

### Anurag98524 commented May 1, 2020

 def computepay(h,r): if h > 40: p = 1.5 * r * (h - 40) + (40 *r) else: p = h * r return p hrs = input("Enter Hours:") hr = float(hrs) rphrs = input("Enter rate per hour:") rphr = float(rphrs) p = computepay(hr,rphr) print('Pay',p)

### Lynthepeoplee commented May 4, 2020

 def computepay(hrs, rate): if hrs > 40: p = (hrs - 40) * 1.5 * rate + 40 * rate else: p = hrs * rate return p h = input("Enter Hours:") hrs = float(h) r = input("Enter Rate:") rate = float(r) p = computepay(hrs, rate) print("Pay", p)

### tarunkumararcot commented May 19, 2020

 def computepay(h,r): if h > 40: p = 1.5 * r * (h - 40) + (40 *r) else: p = h * r return p hrs = input("Enter Hours:") hr = float(hrs) rphrs = input("Enter rate per hour:") rphr = float(rphrs) p = computepay(hr,rphr) print("Pay",p)

### tarunkumararcot commented May 19, 2020

 def computepay(h,r): if h > 40: p = 1.5 * r * (h - 40) + (40 *r) else: p = h * r return p hrs = input("Enter Hours:") hr = float(hrs) rphrs = input("Enter rate per hour:") rphr = float(rphrs) p = computepay(hr,rphr) print("Pay",p) This the right one..I got it right

### sedategrower commented May 25, 2020

 1.5 * r * (h - 40) + (40 *r) from computation , I get different figures , could you please explain how come it gives the 498.75 ok as per definition of the program pay rate for up to 40 hours is suppose x and above 40 hours is 1.5x . Divide this equation in 2 part 1st is (40 r) which compute the pay of 40 hours. 2nd part is 1.5 * r * (h - 40) which computes the pay for hours > 40. here h is 45 so divide in 40 + 5. for 40 hours pay rate is x and for 5 hours pay rate is 1.5x. total pay rate is payrate(40 hours) +payrate(hour>40) . so compute the 1st part 4010.50= 420 now compute 2nd part (45-40) 1.510.50 = 51.510.50=78.75 . now add 1st part and second part 420+78.75=498.75. try is for 52 hours . 1st part 4010.50=420 and 2nd part (52-40)1.510.50=121.510.50=189. s0 answes is 1st part+ 2nd part = 420+189=609. try this value on your code

### Vishvesh482003 commented May 25, 2020

 4.6 Write a program to prompt the user for hours and rate per hour using input to compute gross pay. Pay should be the normal rate for hours up to 40 and time-and-a-half for the hourly rate for all hours worked above 40 hours. Put the logic to do the computation of pay in a function called computepay() and use the function to do the computation… def computepay(h,r): if h > 40: p = 1.5 * r * (h - 40) + (40 *r) else: p = h * r return p hrs = input("Enter Hours:") hr = float(hrs) rphrs = input("Enter rate per hour:") rphr = float(rphrs) p = computepay(hr,rphr) print("Pay",p) It is the right answer

### Chhetri-9901 commented May 27, 2020

 Can i get an explanation for the "time-and-a-half for the hourly rate for all hours worked above 40 hours" and how is that 1.5 coming?

### 7744RB commented May 30, 2020

 hours = input("Enter Hours:") rate = input("Enter Rate:") if int(hours) <= 40: def computepay(hours, rate): wages = int(hours) * float(rate) return wages x = computepay(hours, rate) print("Pay: ") + str(x) else: overhours = int(hours) - 40 def computepay(overhours, rate): wages = (int(overhours) * float(rate) * 1.5) + (40 * float(rate)) return wages x = computepay(overhours, rate) print("Pay",x)

### Lekhram96 commented May 31, 2020

 def computepay(h,r): if h>40: pay=1.5r(h-40)+(40r) else: pay=hr return pay hrs=input ("Enter Hours:") hr=float (hrs) rphrs=input ("Enter rate per hour:") rphr=float (rphrs) p=computepay(hr,rphrs) print("pay",p)

### Droid-Rayhan commented May 31, 2020

 Please tell me what is the problem in this code? It runs but the result doesn't match. def computepay(x,y): return x*y h= input('Enter Hours:') r=input('Enter Payment Per Hour:') fh=float(h) fr=float(r) p= computepay(fh,fr) if fh<=40: print('Pay',computepay(fh,fr)) elif fh>40: print('Pay',computepay(fh,fr)+((fh-40)1.510.50))

### benopoku commented Jun 4, 2020

 #Bernard hrs = input("Enter Hours:") hr = float(hrs) rts = input("Enter rate per hour:") rt = float(rts) def computepay(h,r): if h > 40: p = (40*r) + 1.5 * r * (h-40) else: p = h * r return p p = computepay(hr,rt) print("Pay",p)

### Junaid20001 commented Jun 7, 2020

 def computepay(h,r): if h > 40: p = 1.5 * r * (h - 40) + (40 *r) else: p = h * r return p hrs = input("Enter Hours:") hr = float(hrs) rphrs = input("Enter rate per hour:") rphr = float(rphrs) p = computepay(hr,rphr) print('Pay',p)

### Arjun-Biswas commented Jun 11, 2020

 hours= input("enter hours: ") h= float(hours) rate= input("enter rate: ") r= float(rate) def computepay(h,r): if h<=40: k= h*r else: k = (40 * r) + 1.5 * (h - 40) * r return k print("Pay",computepay(h,r))

# I got it right (indent properly

)
def computepay(h,r):
if h > 40:
p = 1.5 * r * (h - 40) + (40 *r)
return p
else:
p = h * r
return p
hrs = input("Enter Hours:")
hr = float(hrs)
rphrs = input("Enter rate per hour:")
rphr = float(rphrs)

p = computepay(hr,rphr)

print("Pay "+ str(p))

### chaltidutta commented Jun 15, 2020

 def computepay(h,r): if h > 40: p = 1.5 * r * (h - 40) + (40 *r) else: p = h * r return p hrs = input("Enter Hours:") hr = float(hrs) rphrs = input("Enter rate per hour:") rphr = float(rphrs) p = computepay(hr,rphr) print(p) i have done it,but saying error,but why??

### AmanRaut1111 commented Jun 17, 2020

 def computepay(hours, rate) : if hours > 40 : reg = rate * hours otp = (hours - 40.0) * (rate * 0.5) pay = reg + otp else: pay = hours * rate return pay sh = input ("Enter Hours: ") sr = input ("Enter rate : ") fh = float(sh) fr = float(sr) xp = computepay(fh, fr) print("Pay",xp) -----------------------------100%work-----------------------------------

### AmanRaut1111 commented Jun 17, 2020

 def computepay(h,r): if h > 40: p = 1.5 * r * (h - 40) + (40 *r) else: p = h * r return p hrs = input("Enter Hours:") hr = float(hrs) rphrs = input("Enter rate per hour:") rphr = float(rphrs) p = computepay(hr,rphr) print(p) i have done it,but saying error,but why?? try this def computepay(hours, rate) : if hours > 40 : reg = rate * hours otp = (hours - 40.0) * (rate * 0.5) pay = reg + otp else: pay = hours * rate return pay sh = input ("Enter Hours: ") sr = input ("Enter rate : ") fh = float(sh) fr = float(sr) xp = computepay(fh, fr) print("Pay",xp)

### Nishagupta14 commented Jun 17, 2020

 can anyone explain how 1.5 is coming for time-and-a half hourly hours.?

### Mansi612 commented Jun 19, 2020

 shows error in line 4??

### AmanRaut1111 commented Jun 19, 2020

 shows error in line 4?? what is an error ?

### tanishq-agarwal commented Jun 20, 2020

 Smallest code: def computepay(hr,ra): if hr<=40: p=hrra else: p=(hr-40)1.5ra+(40ra) return p hrs = input("Enter Hours:") hr=float(hrs) rate= input("Enter rate:") ra= float(rate) p = computepay(hr,ra) print("Pay",p)

### himanshusengar00 commented Jun 21, 2020

 def computepay(h,r): if h > 40: p = 1.5 * r * (h - 40) + (40 *r) else: p = h * r return p hrs = input("Enter Hours:") hr = float(hrs) rphrs = input("Enter rate per hour:") rphr = float(rphrs) p = computepay(hr,rphr) print("Pay",p) WORKING 100% ****

### aditimalkar commented Jun 21, 2020

 def computepay(hrs, rate): if float(hrs) > 40: p = 1.5 * float(r) * (float(h) - 40) + (40 * float(r)) else: p = hrs * rate return p h = input("Enter Hours:") hrs = float(h) r = input("Enter Rate:") rate = float(r) p = computepay(hrs, rate) print("Pay", p)

### Shubhamsingh09 commented Jun 21, 2020

 def computepay(h,r): if h > 40: p = 1.5 * r * (h - 40) + (40 *r) else: p = h * r return p hrs = input("Enter Hours:") hr = float(hrs) rphrs = input("Enter rate per hour:") rphr = float(rphrs) p = computepay(hr,rphr) print("Pay", p) 100% right compiled and tested

### astha-29 commented Jun 24, 2020

 def computepay(h,r): if h > 40: p = 1.5 * r * (h - 40) + (40 *r) else: p = h * r return p hrs = input("Enter Hours:") hr = float(hrs) rphrs = input("Enter rate per hour:") rphr = float(rphrs) p = computepay(hr,rphr) print("Pay",p)

### LaibaMemon commented Jun 25, 2020

 why its showing be like that? anybody can help me out plz

### AmanRaut1111 commented Jun 25, 2020

 why its showing be like that? anybody can help m why its showing be like that? anybody can help me out plz Try this def computepay(hours, rate) : if hours > 40 : reg = rate * hours otp = (hours - 40.0) * (rate * 0.5) pay = reg + otp else: pay = hours * rate return pay sh = input ("Enter Hours: ") sr = input ("Enter rate : ") fh = float(sh) fr = float(sr) xp = computepay(fh, fr) print("Pay",xp

### FouziaMozumder commented Jun 25, 2020

 ------------This gonna work in a best way------- def computepay(h,r): if h > 40: p = 1.5 * r * (h - 40) + (40 *r) else: p = h * r return p hrs = input("Enter Hours:") hr = float(hrs) rphrs = input("Enter rate per hour:") rphr = float(rphrs) p = computepay(hr,rphr) print("Pay",p)

### dileepachuthan commented Jun 26, 2020 • edited

 #check it out guys def computepay(h,r): if(h <= 40): return h*r else: return 1.5 * h * r hrs = input("Enter Hours:") h = float(hrs) rt = input("Enter rate:") r = float(rt) p = computepay(h,r) print("Pay",p)

### HARSHITH-AH commented Jun 26, 2020

 IS THIS CORRECT? def computepay(h,r): if h<=40 p=h*r else h>40 p= 1.5 * r * (h - 40) + (40 *r) return p hrs = input("Enter Hours:") h=float(hrs) rate=input("enter rate") r=float(rate) p = computepay(10,20) print("Pay",p)

### rpkunn commented Jun 28, 2020

 why its showing be like that? anybody can help m why its showing be like that? anybody can help me out plz Case sensitive for "pay".. try "Pay"

### LaibaMemon commented Jun 28, 2020

 i try this too but its not working Virus-free. www.avast.com <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2> … On Sun, 28 Jun 2020 at 19:41, rpkunn ***@***.***> wrote: ***@***.**** commented on this gist. ------------------------------ [image: image] why its showing be like that? anybody can help m [image: image] why its showing be like that? anybody can help me out plz Case sensitive for "pay".. try "Pay" — You are receiving this because you commented. Reply to this email directly, view it on GitHub , or unsubscribe .

### Bunnyboy01 commented Jul 9, 2020

 def computepay(h,r): if h > 40: p = 1.5 * r * (h - 40) + (40 *r) else: p = h * r return p h = float(input("Enter Hours: ")) r = float(input("Enter rate per hour: ")) p = computepay(h,r) print("Pay",p)

### parndesai16 commented Jul 10, 2020

 def computepay(h,r): if h > 40: p = 1.5 * r * (h - 40) + (40 *r) else: p = h * r return p hrs = input("Enter Hours:") hr = float(hrs) rphrs = input("Enter rate per hour:") rphr = float(rphrs) p = computepay(hr,rphr) print("Pay", p) #i got it right #100%working

### designeranup commented Jul 10, 2020

 #This code will be 100% working def computepay(h, r) : if h > 40 : p = 40 * r + (h - 40) * 1.5 * r else : p = h * r return p h = float(input("Enter Hours")) r = float(input("Enter Rate")) p = computepay(h, r) print("Pay", p)

### piston97 commented Jul 16, 2020

 def computepay(hrs,rph): if hrs < 40: gp = rph * hrs return gp elif hrs > 40: gp = 1.5 * r * (h - 40) + (40 *r) return gp h = float(input('enter the hours ')) r = float(input('enter the rate per hour ')) hrs = h rph = r p = computepay(h,r) print('Pay',p)

### Garv44 commented Jul 16, 2020

 why its showing be like that? anybody can help me out plz P is in "CAPS" in PAY

### som983 commented Jul 20, 2020

 def computepay(h,r): if h>40: p=(1.5*(h-40)r)+(40r) else: p=40*r return p hrs =input("Enter Hours:") h=float(hrs) rate =input("Enter rate per hour:") r=float(rate) p = computepay(h,r) print("Pay",p)

### som983 commented Jul 20, 2020

 this is working perfectly.try it

### mehreen-khan commented Jul 20, 2020

 def computepay(h,r): if h > 40: p = 1.5 * r * (h - 40) + (40 *r) else: p = h * r return p hrs = input("Enter Hours:") hr = float(hrs) rphrs = input("Enter rate per hour:") rphr = float(rphrs) p = computepay(hr,rphr) print("Pay", p) the above code gave an error of - Pay None and if checked with hours less than 40, it gives out atleast an answer. on the otherhand, I made it work by slightly making some changes- def computepay(h,r): if h<=40: p= hr else: p = (40r)+1.5*(h-40)*r return p hrs = input("Enter Hours:") hr = float(hrs) rphrs =("Enter rate per hour") rphr = float(rphrs) p = computepay(hr,rphr) print("Pay",p) Can somebody help me figure, why the earlier code is not working properly.

### akashnakod commented Jul 21, 2020

 hrs = input("Enter Hours:") hra=float(hrs) rate=input("Enter rate:") raa=float(rate) if hra<=40: def computepay(hra,raa): multiply=hra*raa return multiply else: def computepay(hr,ra): hr=hraraa ra=(hra-40.0)(raa*0.5) p=hr+ra return p p = computepay(hra,raa) print("Pay",p)

### JoseLuis-Luna commented Jul 27, 2020

 def computepay(h,r): ``````if h > 40: p= (40*r)+(h-40)*(1.5*r) else: p= h*r return p `````` hrs = input("Enter Hours:") hr= float (hrs) rate = input ("Enter Rate:") rt= float(rate) p = computepay(hr,rt) print("Pay",p)

### iyashjayesh commented Jul 30, 2020

 def computepay(hours,rate): if hours>40.0: p = 1.5rate(hours-40) +(40rate) else: p = ratehours return p hours=input("Enter Hours:") hour= float(hours) rphrs = input("Enter rate per hours:") rphr = float(rphrs) p= computepay(hour,rphr) print("Pay:",p)

### pushiko28 commented Aug 11, 2020

 1.5 * r * (h - 40) + (40 *r) from computation , I get different figures , could you please explain how come it gives the 498.75 is because you should use 0.5 (the midle with decimals) and not 1.5.

### jonbarba commented Aug 14, 2020 • edited

 #Many people are getting this wrong because they keep multiplying the overtime rate by 1.5 you need to multiply it by 0.5 def computepay(r): if h > 40: pays = (h - 40) * (0.5 * r) + (h * r) return pays elif h <= 40: pays = h * r return pays hrs = input("Enter Hours: ") h = float(hrs) rate = input("Enter rate per hour: ") r = float(rate) print("Pay",computepay(r))

### NaelZaino commented Aug 27, 2020

 I used this code and it worked: def computepay(h,r): if h > 40: p = 1.5 * r * (h - 40) + (40 *r) else: p = h * r return p h = input("Enter Hours:") h = float(h) r = input("Enter rate per hour:") r = float(r) p=computepay(h,r) print("Pay",p)

### NaelZaino commented Aug 27, 2020

 you can also make it shorter by combining the float and input together like the following: def computepay(h,r): if h > 40: p = 1.5 * r * (h - 40) + (40 *r) else: p = h * r return p h = float(input("Enter Hours:")) r = float(input("Enter rate per hour:")) p=computepay(h,r) print("Pay",p)

### NaelZaino commented Aug 27, 2020

 why its showing be like that? anybody can help me out plz change print "pay" to capital P

### WardaLiaqat01 commented Sep 2, 2020

 #4.6 Write a program to prompt the user for hours and rate per hour using input to compute gross pay. Pay should be the normal rate for hours up to 40 and time-and-a-half for the hourly rate for all hours worked above 40 hours. Put the logic to do the computation of pay in a function called computepay() and use the function to do the computation. The function should return a value. Use 45 hours and a rate of 10.50 per hour to test the program (the pay should be 498.75). You should use input to read a string and float() to convert the string to a number. Do not worry about error checking the user input unless you want to - you can assume the user types numbers properly. Do not name your variable sum or use the sum() function. def computepay(h,r): if h > 40: p = 1.5 * r * (h - 40) + (40 *r) else: p = h * r return p hrs = input("Enter Hours:") hr = float(hrs) rat = input("Enter Rate per hour:") rph = float(rat) p = computepay(hr,rph) print("Pay",p)

### bhartimeena commented Sep 8, 2020

 shows error in line 4?? what is an error ? def computepay(h,r): if h > 40: p = 1.5 * r * (h - 40) + (40 *r) else: p = h * r return p hrs = input("Enter Hours:") hr = float(hrs) rphrs = input("Enter rate per hour:") rphr = float(rphrs) p = computepay(hr,rphr) print(p)

### bhartimeena commented Sep 8, 2020

 you should try this it's work 100%%%%%

### araujolaura commented Sep 14, 2020

 def computepay(h,r): if h > 40: p = 1.5 * r * (h - 40) + (40 *r) else: p = h * r return p hrs = input("Enter Hours:") hr = float(hrs) rphrs = input("Enter rate per hour:") rphr = float(rphrs) p = computepay(hr,rphr) print("Pay",p) you're welcome!

### Nephy2911 commented Sep 15, 2020

 def computepay(h,r): if h > 40: p = 0.5 * r * (h-40) + (h * r) else: p = h * r return p hrs = input("Enter Hours: ") hr = float(hrs) rate = input("Enter Rate: ") rte = float(rate) p = computepay(hr,rte) print("Pay",p)

### bhartimeena commented Sep 16, 2020

 shows error in line 4?? Yeah same error I got but when I give a tab after if and else statement it's run perfectly.

### darshanghadi007 commented Sep 24, 2020

 def computepay(h,r): if h > 40: p = 1.5 * r * (h - 40) + (40 *r) else: p = h * r return p hrs = input("Enter Hours:") hr = float(hrs) rphrs = input("Enter rate per hour:") rphr = float(rphrs) p = computepay(hr,rphr) print("Pay",p)

### Thrinesh15 commented Sep 30, 2020

 Guys can anyone send the correct code for the following question Write a program to prompt the user for hours and rate per hour using input to compute gross pay. Pay should be the normal rate for hours up to 40 and time-and-a-half for the hourly rate for all hours worked above 40 hours. The output should be 498.75

### ironemin1k commented Oct 5, 2020

 def computepay(h,r): if h > 40: p = 1.5 * r * (h - 40) + (40 *r) else: p = h * r return p hrs = input("Enter Hours:") hr = float(hrs) rphrs = input("Enter rate per hour:") rphr = float(rphrs) p = computepay(hr,rphr) print("Pay", p) #Guys! just add a space last line. don't forget this assigment very sensitive.

### Thrinesh15 commented Oct 5, 2020

 Thank you So much

### Harsha4747 commented Oct 9, 2020

 def computepay(h,r): if h>40: return 40r+(h- 40)r1.5 else: return hr hrs=float(input("enter hours:") r=float(input("enter rate per hour:") p=computepay(hrs,r) print("pay",p)

### Harsha4747 commented Oct 9, 2020

 Coming error

### Harsha4747 commented Oct 9, 2020

 Thank you So much Bro coming error

### bhartimeena commented Oct 9, 2020

Thank you So much
Bro coming error

def computepay(h,r):
if h > 40:
p = 1.5 * r * (h - 40) + (40 *r)
else:
p = h * r
return p

hrs = input("Enter Hours:")
hr = float(hrs)
rphrs = input("Enter rate per hour:")
rphr = float(rphrs)

p = computepay(hr,rphr)
print("Pay",p)

## you can try this!!

### Nephy2911 commented Oct 13, 2020

 Remove "Pay" at the end it just wants p in the desired output. print(p) … On Tue, Oct 13, 2020, 11:27 AM HarisTalas ***@***.***> wrote: *@HarisTalas* commented on this gist. ------------------------------ [image: image] every time come mismatch where error? — You are receiving this because you commented. Reply to this email directly, view it on GitHub , or unsubscribe .

### arjunrajapeta commented Oct 29, 2020

 def computepay(hrs,rate): if float(hrs) > 40: pay = (40*float(rate)) + (float(hrs) -40) * float(rate) * 1.5 return pay else: pay = float(hrs)*float(rate) return pay hrs = input("Enter Hours:") rate = input("Enter Rate:") p = computepay(hrs,rate) print("Pay" ,p)

### luissantaanna commented Nov 3, 2020

 def computepay(h,r): if h > 40: p = 1.5 * r * (h-40) + (40*r) else: p = h * r return p hrs = input("Enter Hours: ") h = float(hrs) rate = input("Enter Rate: ") r = float(rate) p = computepay(h,r) print("Pay",p)

### Sohanaafroz955 commented Nov 4, 2020

 def computepay(h,r): if h > 40: p = 1.5 * r * (h - 40) + (40 *r) else: p = h * r return p hrs = input("Enter Hours:") hr = float(hrs) rphrs = input("Enter rate per hour:") rphr = float(rphrs) p = computepay(hr,rphr) print("Pay",p)

### Laksara1997 commented Nov 23, 2020

 def computepay(h,r): if h > 40: p = 1.5 * r * (h - 40) + (40 *r) else: p = h * r return p hrs = input("Enter Hours:") hr = float(hrs) rphrs = input("Enter rate per hour:") rphr = float(rphrs) p = computepay(hr,rphr) print("Pay",p) this is right answer

### MR-Robot2001 commented Nov 25, 2020

 def computepay(h,r): if h > 40: p = 1.5 * r * (h - 40) + (40 *r) else: p = h * r return p hrs = input("Enter Hours:") hr = float(hrs) rphrs = input("Enter rate per hour:") rphr = float(rphrs) p = computepay(hr,rphr) print("Pay",p) //Perfect code