Skip to content

Instantly share code, notes, and snippets.

@KKarthikeya
Created August 16, 2015 04:19
Show Gist options
  • Save KKarthikeya/0696fe56a97c0699c3c5 to your computer and use it in GitHub Desktop.
Save KKarthikeya/0696fe56a97c0699c3c5 to your computer and use it in GitHub Desktop.
Write a program to prompt the user for hours and rate per hour using raw_input to compute gross pay. Award time-and-a-half for the hourly rate for all hours worked above 40 hours. Put the logic to do the computation of time-and-a-half in a function called computepay() and use the function to do the computation. The function should return a valu…
def computepay(hours,rate):
if hours>40.0:
p = rate * 40.0
p = p+(1.5*rate*(hours-40))
else:
p = rate*hours
return p
hours = float(raw_input("Enter worked hours: "))
rate = float(raw_input("Enter Pay rate per hour: "))
print computepay(hours,rate)
@MsBold
Copy link

MsBold commented May 14, 2020

Hello all! I should have updated you all on my progress. My apologies. I actually completed this assignment. Your help is greatly appreciated. :)

@akanksha207
Copy link

Hello everyone!
Can someone plz help me with this problem? I am repeatedly getting the error with this code

@Kiaracl
Copy link

Kiaracl commented May 23, 2020

Hi guys!!! here's my answear!! I hope it helps you...

def computepay(x,y):
if x>40:
sub = (x - 40) * 1.5
x = 40 + sub
pay = x * y
return pay
ux = input("Enter hour:")
uy = input("Enter rate:")
try:
x = float(ux)
y = float(uy)
except:
print("error,please enter numeric input")
quit()
h=computepay(x,y)
print("Pay",h)

@rubisinghchauhan123
Copy link

Its not working....its shows error in 2nd line...plz help me ....that how I can solve it..

@4kaushik
Copy link

I am getting an error message "Invalid Syntax"

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

@Anuja2512
Copy link

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

@Rutika26
Copy link

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)

@abdoulayegk
Copy link

working 100%
def salary (hours,rate):
if hours<=40:
p=hoursrate
return p
else:
p=(40
rate)+((hours-40)1.5rate)
return p

hours=float(input('Enter Hours:'))
rate=float(input('Enter Rate:'))

pay = salary(hours,rate)

print(pay)

@jamesrozet
Copy link

type mismatch ???????

@abdoulayegk
Copy link

Can you used your own editor to check the results before submitting the code.
As for me I worked fine.

@abdoulayegk
Copy link

You can also paste your code here so that you can get help

@sourav091998
Copy link

I'm stuck in assignments 4.6,, plz help me

@abdoulayegk
Copy link

@sourav091998
are you still needing help?

@Tarun661
Copy link

Im getting error in line 2 I have tried ur code

@abdoulayegk
Copy link

Can you post the error message here

@abdoulayegk
Copy link

And the question as well. Remember that some time questions are different from person to person

@persephone997
Copy link

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

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

Pay = computepay(h,r)
print("Pay", Pay)

It works!!!!!!!!!! please use this code~

@abdoulayegk
Copy link

@persphone997 why didn't you use the try except block?

@persephone997
Copy link

@persphone997 why didn't you use the try except block?

Cause the original code he gave us is:
def computepay(h,r):
return 42.37

hrs = input("Enter Hours:")
p = computepay(10,20)
print("Pay",p)

So it definitely wants to improve on that.

@abdoulayegk
Copy link

But in the description did they ask you to use try except or not?

@persephone997
Copy link

But in the description did they ask you to use try except or not?

For me.
Nope.

@abdoulayegk
Copy link

Okay then I hope they accepted your code right?

@persephone997
Copy link

persephone997 commented Jul 10, 2020 via email

@abdoulayegk
Copy link

Well done

@creativetareq
Copy link

def computepay(hours,rate):
if hours>40.0:
p = rate * 40.0
p = p+(1.5rate(hours-40))
else:
p = rate*hours
return p
hours = float(raw_input("Enter worked hours: "))
rate = float(raw_input("Enter Pay rate per hour: "))
p=(computepay(hours,rate))
print("Pay",p)

@ShivamRai21
Copy link

ShivamRai21 commented Jul 28, 2020

This code is definitely gonna run on any platform.
Just try it once.

def computepay(h,r):
if h>40.0:
p=1.5 * float(r) * (h-40.0)+(40.0 * float(r))
else:
p=h*r
return p
hrs = input("enter hours:")
a=float (hrs)
rate = input("enter rate per hour:")
b=float(rate)
p=computepay(a,rate)
print("Pay",p)

@mihir16799
Copy link

help me my code is not running

@shamilhzm
Copy link

solution without def

hrs = input("Enter Hours:")
h = float(hrs)
rate = input("Enter Pay Rate:")
r = float(rate)
pay = hr
otpay = 40
r + (h-40)r1.5
if h<=40:
print(pay)
else:
print(otpay)

@samriddhitiwari
Copy link

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% working

Assignment 4 6

Thanks!!!!!!! a tonnnnn it really worked

@shivamgupta6588
Copy link

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

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

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