Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jennyonjourney/e4982d3fedd6c70f1da239f86f1918b7 to your computer and use it in GitHub Desktop.
Save jennyonjourney/e4982d3fedd6c70f1da239f86f1918b7 to your computer and use it in GitHub Desktop.
Python for everybody - Assignment 4.6
def computepay(h,r):
if h<=40:
pay=h*r
elif h>40:
pay=40*r+(h-40)*r*1.5
return(pay)
hrs = input("Enter Hours:")
h = float(hrs)
rate = input("Enter rate:")
r = float(rate)
p = computepay(h,r)
print(p)
@AhmedSaidi99
Copy link

def computepay(h,r):
if h<=40:
pay=hr
elif h>40:
pay=40
r+(h-40)r1.5
return(pay)

hrs = input("Enter Hours:")
h = float(hrs)
rate = input("Enter rate:")
r = float(rate)
p = computepay(h,r)
print("Pay", p)

@MimAhmed
Copy link

def computepay(h,r):
if h<=40:
pay=hr
elif h>40:
pay=40
r+(h-40)r1.5
return(pay)

hrs = input("Enter Hours:")
hour_float = float(hrs)
rate = input("Enter rate:")
rate_float = float(rate)
final_pay = computepay(hour_float ,rate_float)
print(final_pay)

@HaamzaHM
Copy link

def computepay(h,r):
if h<=40:
pay=hr
elif h>40:
pay=40
r+(h-40)r1.5
return(pay)

hrs = input("Enter Hours:")
h = float(hrs)
rate = input("Enter rate:")
r = float(rate)
p = computepay(h,r)
print("Pay",p)

@Japarna
Copy link

Japarna commented Oct 20, 2020

hrs= input("enter the hours:")
rate=input("enter the rate per hour:")
hrs=float(hrs)
rate=float(rate)
def computepay(hours,rate):
if hrs <= 40:
pay=hrs

elif hrs >40:
    pay=40*rate+(hrs-40)*rate*1.5
    return (pay)

pay=computepay(hrs,rate)
print('Pay',pay)

@JohnLeMay4
Copy link

Why isn't this working? It is literally what Chuck did in the video and it works in my command prompt:

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

print("Pay:",xp)

@JohnLeMay4
Copy link

Why isn't this working? It is literally what Chuck did in the video and it works in my command prompt:

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

print("Pay:",xp)

IT WAS THE COLON IN THE FINAL PRINT STATEMENT. I AM GOING TO SLEEP. Whew.

@sisysl
Copy link

sisysl commented Jan 22, 2021

hrs = input("Enter Hours:")
h = float(hrs)
rate = input("Enter rate:")
r = float(rate)

def computepay(h,r):
if h<=40:
pay=h_r elif h>40: pay=40_r+(h-40)_r_1.5
return(pay)
p = computepay(h,r)
print('Pay',p)

not working

It is working, try again.

Be careful for indent when use function.

@ozguripekci
Copy link

#Perfectly Working 💙

#function
def computepay(hours, per_rate_hours):

    #overtime

    if (hours>40):
        pay = hours * per_rate_hours
        overtime = (hours - 40)   * (0.5 * per_rate_hours)
        payment = pay + overtime

    else:
        payment = hours * per_rate_hours
    return payment


#code begins
hours = input("Enter Hours: ")
per_rate_hours = input("Enter Per Rate Hour: ")


#try and except
try:
	f_hours= float(hours)
	f_per_rate_hours=float(per_rate_hours)
except:
    print("Error")
    quit()

final_pay = computepay(f_hours, f_per_rate_hours)
print("Pay", final_pay)

@sooryansatheesh
Copy link

#Perfectly Working 💙

#function
def computepay(hours, per_rate_hours):

    #overtime

    if (hours>40):
        pay = hours * per_rate_hours
        overtime = (hours - 40)   * (0.5 * per_rate_hours)
        payment = pay + overtime

    else:
        payment = hours * per_rate_hours
    return payment


#code begins
hours = input("Enter Hours: ")
per_rate_hours = input("Enter Per Rate Hour: ")


#try and except
try:
	f_hours= float(hours)
	f_per_rate_hours=float(per_rate_hours)
except:
    print("Error")
    quit()

final_pay = computepay(f_hours, f_per_rate_hours)
print("Pay", final_pay)

You will get an error "You have to prompt for the data"...

@sooryansatheesh
Copy link

def computepay():
hours = float(input("Enter Hours:"))
rate_per_hour = float(input("Enter Rate per hour:"))
if hours>40:
pay=(40rate_per_hour)+((hours-40)rate_per_hour1.5)
else :pay=(hours
rate_per_hour)
return pay

print("Pay",computepay())
quit()

my code above gives the exact answer but the autograder rejects it by telling that you must prompt for the data

@MuhammadShayan17
Copy link

not working

it's because of the indent issue in line 6; the return function should be backwards, and with the de-indent apart from the above line..
Then I hope that the above code would have worked just right and fine.. :)

@MuhammadShayan17
Copy link

input("Enter Hours:")
h=float(hrs)
rate=input("enter rate")
r=float(rate)
def computepay(h,r):
if h<=40:
pay=hr
elif h>=40:
pay=40r+(h-40)1.5r
return (pay)
p=computepay(h,r):
print("Pay",p)
I don;t see what is wrong with this code. It comes up as a parse error. Can someone please help

The only thing I find wrong in this programming code is the "indent" thing, as I think, you totally forgot about using indents and all..

@MuhammadShayan17
Copy link

Why isn't this working? It is literally what Chuck did in the video and it works in my command prompt:
def computepay(hours, rate) :
#print("In computepay", hours, rate)
if hours > 40 :
reg = rate * hours
otp = (hours - 40.0) * (rate * 0.5)
pay = reg + otp
else:
pay = hours * rate
#print("Returning",pay)
return pay
sh = input("Enter Hours: ")
sr = input("Enter Rate: ")
fh = float(sh)
fr = float(sr)
xp = computepay(fh,fr)
print("Pay:",xp)

IT WAS THE COLON IN THE FINAL PRINT STATEMENT. I AM GOING TO SLEEP. Whew.

Hmm, right, but along with this, I guess, there's also the indent thing issue here.. But nvm, all's good when the end's good I guess.. :/

@MuhammadShayan17
Copy link

def computepay():
hours = float(input("Enter Hours:"))
rate_per_hour = float(input("Enter Rate per hour:"))
if hours>40:
pay=(40_rate_per_hour)+((hours-40)_rate_per_hour_1.5) else :pay=(hours_rate_per_hour)
return pay

print("Pay",computepay())
quit()

my code above gives the exact answer but the autograder rejects it by telling that you must prompt for the data

Just look for the indent here, I guess. Apart from this, I think the autograder might also be not scanning and coding the double function you've put and typed out there, so yeaah...

@ozguripekci
Copy link

Sometimes, "copy and paste" is not working. You need to write all code one-by-one on your IDE.
And sometimes because of the "copy and paste", indent problems come through.
Best wishes guys.

@iamfusta
Copy link

#fixed TR_iamfusta

hrs = input("Enter Hours:")
h = float(hrs)
rate = input("Enter rate:")
r = float(rate)

def computepay(h,r):
if h<=40:
pay=hr
elif h>40:
pay=40*r+(h-40)r1.5
return(pay)
p = computepay(h,r)
print('Pay',p)

@dynamodave789
Copy link

def computepay(h, r):
if h <= 40:
pay = h * r
elif h > 40:
pay = (40*r+(h-40)1.5r)
return(pay)

hrs = input("Enter Hours: ")
h = float(hrs)
rate = input("Enter Rate: ")
r = float(rate)
p = computepay(h, r)
print("Pay", p)

quit()

@eddshine
Copy link

eddshine commented May 6, 2022

Here's my code:
(Only 9 lines of code plus it's very easy to understand)

def computepay(h, r):
    if h <= 40:
        return h * r
    else:
        return (h * r) + ((h-40) * (r/2))

hrs = float(input("Enter Hours: "))
rate = float(input("Enter Rate: "))

p = computepay(hrs, rate)
print("Pay", p)

Have fun! :)

@aliimran-ux
Copy link

This is perfect code 👍

def computepay(h,r):
if h<=40:
pay=hr
elif h>40:
pay=40
r+(h-40)r1.5
return(pay)

hrs = input("Enter Hours:")
h = float(hrs)
rate = input("Enter rate:")
r = float(rate)
p = computepay(h,r)
print("Pay", p)

@sunnyfisher429
Copy link

how can i fix this ?

hrs= input("Enter Hours:")
rates=input("Enter hours:")
h=float(hrs)
r=float(rates)

def computepay(hrs,rates)
if h>=40:
p=(40+(fh-40))r(fr1.5)
else h<=40:
p=h
r
return(p)

sp=computepay(h,r)
print ('Pay',p)

@imranlondon
Copy link

imranlondon commented Sep 17, 2022

pay and over time caculater

def computepay(hours, rates):
if hours <= 40:
print(hours * rates)
else:
print ((hours - 40) * (rates * 1.5) + (40 * rates))

If hours are more than 40, the mean user did over time, and the rate differs from the actual rate. So, first, we count extra hours from 40, then multiply with different rates and then the original hours at the regular rate. Then combine both.

Taking input from user

hours = float(input("Enter hours :"))
rates = float(input("Enter rates :"))

called function

computepay(hours,rates)

@sbedoyac
Copy link

sbedoyac commented Nov 4, 2022

Why isn't this working? It is literally what Chuck did in the video and it works in my command prompt:
def computepay(hours, rate) :
#print("In computepay", hours, rate)
if hours > 40 :
reg = rate * hours
otp = (hours - 40.0) * (rate * 0.5)
pay = reg + otp
else:
pay = hours * rate
#print("Returning",pay)
return pay
sh = input("Enter Hours: ")
sr = input("Enter Rate: ")
fh = float(sh)
fr = float(sr)
xp = computepay(fh,fr)
print("Pay:",xp)

IT WAS THE COLON IN THE FINAL PRINT STATEMENT. I AM GOING TO SLEEP. Whew.

Thaks for that comment, it was the solution

@CristianoFIlho
Copy link

def computepay(hours, rate):
if hours <= 40:
return hours * rate
else:
overtime_hours = hours - 40
overtime_pay = overtime_hours * (rate * 1.5)
return 40 * rate + overtime_pay

hours = float(input("Enter the number of hours worked: "))
rate = float(input("Enter the rate per hour: "))
gross_pay = computepay(hours, rate)
print("Pay %.2f" % gross_pay)

@programmarself
Copy link

its works 100%.
def computepay(h,r):
if h<=40:
pay=hr
elif h>40:
pay=40
r+(h-40)r1.5
return(pay)

hrs = input("Enter Hours:")
h = float(hrs)
rate = input("Enter rate:")
r = float(rate)
p = computepay(h,r)
print("Pay",p)

@silo3605
Copy link

silo3605 commented Jan 19, 2024

This worked for me perfectly, most of the times it has to do with indentations, or Colons or " " improperly placed.
def computepay(h, r):
if hours <= 40:
pay = hours * rate
else:
pay = 40 * rate + (hours - 40) * rate * 1.5
return pay

hours = float(input("Enter hours: "))
rate = float(input("Enter rate per hour: "))

p = computepay(10, 20)
print("Pay", p)

Note: There are indentations in this code: if, else and returned must be aligned; pay, pay must also be aligned. If using python 3, hit the tab key once, which should place if right between f in def and space and c in computepay(h,r): The first pay should be right beneath hours of the if statement. The second pay should be beneath se of the else: and lastly return pay should be in alignment with else: so it should be if hours, else: and return pay aligned correctly and the same for pay by using the space bar in your pc. There two spaces after lines:6 and 10

@CodesbyRohit
Copy link

def computepay(h, r):
if h <= 40:
pay = h * r
elif h > 40:
pay = 40 * r + (h - 40) * r * 1.5
return pay # Corrected indentation

Get user input for hours and rate

hrs = input("Enter Hours: ")
h = float(hrs) # Convert input to float
rate = input("Enter Rate: ")
r = float(rate) # Convert input to float

Calculate pay

p = computepay(h, r)

Print the result

print(p)

Explanation of Changes
Indentation: The return pay statement is now correctly indented to be part of the computepay function.
Input Handling: The input handling remains the same, converting the input strings to floats for calculations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment