-
-
Save ZeroRaven/6c82f2c8e2a2dc327f42c9fe858da3c3 to your computer and use it in GitHub Desktop.
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) |
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)
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.
#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))
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)
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)
#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)
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)
you should try this it's work 100%%%%%
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!
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)
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.
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 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
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.
Thank you So much
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)
Coming error
Thank you So much
Bro coming error
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!!
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)
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)
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)
def computepay(h,r):
if h > 40:
p = 1.5 * r * (h - 40) + (40 *r)
else:
p = h * r
return phrs = 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
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
def computepay(h,r):
if h > 40:
p = 1.5 * r * (h - 40) + (40 *r)
else:
p = h * r
return phrs = 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
![Screenshot 2020-06-21 at 9 27 34 PM](https://user-images.githubusercontent.com/67234874/85229185-172f4a00-b406-11ea-9c39-02a4d13c48ac
def computepay(h,r) :
if h > 40 :
pay = (1.5 * r * (h - 40) + (40 r))
else :
pay= hr
return pay
sh = input ("Enter Hours: ")
sr = input ("Enter rate : ")
fh = float(sh)
fr = float(sr)
xp = computepay(fh, fr)
print("Pay",xp)
###Tested at https://www.py4e.com/ and 100% fine.
def computepay(h,r):
if float(h) > 40:
p = 1.5 * float(r) * (float(h) - 40) + (40 *float(r))
else:
p = float(h) * float(r)
return float(p)
hrs = input("Enter Hours:")
hr = float(hrs)
rphrs = input("Enter rate per hour:")
rphr = float(rphrs)
p = computepay(hrs,rphr)
print("Pay",p)
this code will give you exact result without any error
def computepay(h,r):
hrs = input("Enter Hours:")
hr= float (hrs)
rate = input ("Enter Rate:")
rt= float(rate)
p = computepay(hr,rt)
print("Pay",p)