{{ message }}

Instantly share code, notes, and snippets.

# Mohamed2del/3.1.py

Created Jun 9, 2018
Write a program to prompt the user for hours and rate per hour using input to compute gross pay. Pay the hourly rate for the hours up to 40 and 1.5 times the hourly rate for all hours worked above 40 hours. 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()…
 hrs = input("Enter Hours:") h = float(hrs) xx = input("Enter the Rate:") x = float(xx) if h <= 40: print( h * x) elif h > 40: print(40* x + (h-40)*1.5*x)

### Prity28 commented Jul 5, 2019

 Thank you very much :)

### marcelmarizu commented Feb 10, 2020

 Thank you very much

### sakshipathak29 commented Feb 13, 2020

 why h-40

### anirudhvee commented Mar 3, 2020

 I wrote the greater than instead of lesser than. Phew! thanks

### anirudhvee commented Mar 3, 2020

 why h-40 because of multiplying only the hours ofter 40

### GambhirPalak27 commented Mar 9, 2020

 Thank you!

### YvonneGi commented Apr 11, 2020

 Thank you a lot

### lakshman1-oss commented Apr 27, 2020

 hrs = input("Enter Hours:") h = float(hrs) xx = input("Enter the Rate:") x = float(xx) if h <= 40: print( h * x) elif h > 40: print(40* x + (h-40)1.5x)

### jyotidurga commented Apr 28, 2020

 print(40* x + (h-40)1.5x) can u explain , can't understand

### sahasraa commented Apr 28, 2020

 print(40* x + (h-40)1.5x) is correct if i put those values 45 and 10.5 but how do we get the idea of writing that print(40* x + (h-40)1.5x)?? please explain

### TummaManoj commented May 1, 2020

 print(40* x + (h-40)1.5x) is correct if i put those values 45 and 10.5 but how do we get the idea of writing that print(40* x + (h-40)1.5x)?? please explain hi @sahasraa, how u write is .... it's all about math... code ur write understand the statement..... give ur supporting to it. like verify urself that its matching or not!!! like normally, in this question first we think rate*time.... extra thing what he is asking is extra time u work i'll pay u 1.5 times to the extra work... simple....! understand the statement... then justify your statement what u think Done...! one last thing !!!... dont hestitate or be bored.. start from the level one problems... dont directly check the level 10 problems..... Good Luck :)

### shubham-mishra06 commented May 7, 2020

 hrs = input("Enter Hours:") h = float(hrs) xx= input("Enter the rate:") x=float(xx) if h<=40: print(hx) else: print(40x+(h-40)1.5x) i am getting error in line 7 plz help.

### darshak4497 commented May 8, 2020

 hrs = input("Enter Hours:") h = float(hrs) xx= input("Enter the rate:") x=float(xx) if h<=40: print(h_x) else: print(40_x+(h-40)_1.5_x) i am getting error in line 7 plz help. correct your indentation

### Manthan-Gohel52 commented May 13, 2020

 I done it another way, I don't know if it is the correct way or not, please tell if not, hrs = float(input("Enter Hours:")) rate = float(input("Enter Rate:")) pay = hrs * rate if hrs <= 40: print(pay) else: pay = (((hrs - 40) * rate) / 2) + pay print(pay)

### AKASANCRACY commented May 14, 2020

 else condition is wrong not divide by 2 instead of multiply by 1.5 Thanks with regards, S.PRAKASH,B.Tech,M.Tech(Ph.D) Assistant Professor, Department of ECE, CK College of Engineering & Technology, Cuddalore. PH: 8754917470 … On Thu, May 14, 2020 at 1:00 AM Manthan Gohel ***@***.***> wrote: *@Manthan-Gohel52* commented on this gist. ------------------------------ I done it another way, I don't know if it is the correct way or not, please tell if not, hrs = float(input("Enter Hours:")) rate = float(input("Enter Rate:")) pay = hrs * rate if hrs <= 40: print(pay) else: pay = (((hrs - 40) * rate) / 2) + pay print(pay) — You are receiving this because you commented. Reply to this email directly, view it on GitHub , or unsubscribe .

### rmt1408 commented May 16, 2020

 score=input('Enter score: ') try: sc=float(score) except: print('Sorry, try a number.') quit() if float(score) > 1.0 or float(score) < 0.0 : print('Sorry, not in range') elif float(score) >= 0.9 : print('A') elif float(score) >= 0.8 : print('B') elif float(score) >= 0.7 : print('C') elif float(score) >= 0.6 : print('D') else : print('F')

### Mohit690069 commented May 22, 2020

 why h-40 we have to pay for extra hours 1.5 times the regular pay after that means if i worked 42 hour i have to substract 40 from it

### Cyan-a11y commented Jun 4, 2020

 should use else not elif hrs = input("Enter Hours:") h = float(hrs) xx= input("Enter the Rate:") x = float(xx) if h <= 40: print(h * x) else: print(40*x+(h-40)1.5x)

### jyotidurga commented Jun 5, 2020

 Thanks jyoti Durga … On Wed, 29 Apr 2020, 12:37 am sahasraa, ***@***.***> wrote: ***@***.**** commented on this gist. ------------------------------ print(40* x + (h-40)1.5x) is correct if i put those values 45 and 10.5 but how do we get the idea of writing that print(40* x + (h-40)1.5x)?? please explain — You are receiving this because you commented. Reply to this email directly, view it on GitHub , or unsubscribe .

### Nikita-xo commented Jun 12, 2020 • edited

 Same code but I am getting error on line hrs = input (" Enter Hours: ") Please help me out? Error i : bad input on line 1

### Manthan-Gohel52 commented Jun 12, 2020

 Nikita, can you show me your code?

### jesuszabaletafranco commented Jun 14, 2020

 Thank you

### donny838 commented Jun 18, 2020

 Can someone pls explain what is the purpose of this line? print(40*x+(h-40)1.5x)

### tanishq-agarwal commented Jun 19, 2020

 My solution: hrs = input("Enter Hours:") h = float(hrs) rate = input("Enter Rate:") r=float(rate) if h<=40: hourLate= hr else: hourLate= 40r+(h-40)1.5r print(hourLate)

### mayaramein commented Jun 19, 2020

 Can someone pls explain what is the purpose of this line? print(40*x+(h-40)1.5x) h is hours r is the rate the program is to calculate the gross pay and that by multiple hours in rate but there is a condition and that if the number of hours is above 40 you will calculate the gross pay for the first 40 hours as normal "print(40x" and for the rest of hours we would consider it as ponus by multiple the rate "(1.5*x)"

### Turalito commented Jun 27, 2020 • edited

 Write a program to prompt for a score between 0.0 and 1.0. If the score is out of range, print an error. If the score is between 0.0 and 1.0, print a grade using the following table: Score Grade = 0.9 A = 0.8 B = 0.7 C = 0.6 D < 0.6 F If the user enters a value out of range, print a suitable error message and exit. For the test, enter a score of 0.85. score = input('Enter score: ') sc = float(score) try: sc = float(score) except : print('Sorry try a number.') if 0.0 > sc > 1.0: print('Error: Score is out of range') elif sc >= 0.9 : print("A") elif 0.9 > sc >= 0.8: print("B") elif 0.8 > sc >= 0.7: print("C") elif 0.7 > sc >= 0.6: print("D") else: print("F")

### ghost commented Jun 27, 2020

 Thanks a lot :)

### sugampath commented Jul 3, 2020 • edited

 hrs = int(input("Enter Hours:")) rate=float(input("enter rate per hour:")) if hrs<=40: pay=hrsrate elif hrs>40: pay=40rate+(hrs-40)rate1.5 else: print ("wow") print (pay)

### Bunnyboy01 commented Jul 9, 2020

 a = float(input("Enter Hour: ")) b = float(input("Enter Rate: ")) if a>40: print(40b+(a-40)1.5b) else: print(ab)

### sahil521 commented Jul 13, 2020

 h-40 is for subtraction then you get how many time you work extra an get extra pay

### JalalUddinAkbar commented Jul 18, 2020

 hrs = input("Enter Hours:") h = float(hrs) rate = input("Enter rate: ") r = float(rate) gross = float(h * r) ext = float(h - 40) if h <= 40 : print(gross) else : print( (40 * r) + (ext * r * 1.5))

### a-shebl commented Jul 24, 2020

 hrs = input("Enter Hours:") h = float(hrs) rate = input("enter your rate per hour") r = float(rate) if h>40: a = rh o = (h-40)(1.5r) x = a+o print(x) elif h<40: c = rh print(c)

### Varadashetty commented Jul 28, 2020 • edited

 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): computepay = h+r return computepay hrs = input("Enter Hours:") rate = input("Enter rate:") h = float(hrs) r = float(rate) h = float(hrs) * float(rate) r = 5 * 10.5 * 1.5 p = computepay(h,r) if p <= 40: print("pay") else: print("Pay",p) I am getting "you must prompt for the data"

### sandeshmagar21 commented Aug 1, 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): computepay = h+r return computepay hrs = input("Enter Hours:") rate = input("Enter rate:") h = float(hrs) r = float(rate) h = float(hrs) * float(rate) r = 5 * 10.5 * 1.5 p = computepay(h,r) if p <= 40: print("pay") else: print("Pay",p) I am getting "you must prompt for the data" What question asked is Simple. If users work the over time just pay 1.5 time for the over worked hours. you code is okya uptop r = float(rate), then in the below line you are using the same variable "h" which is already used above. And other i don't know i m just new to python. This i mine you can look it. hrs = input("Enter Hours:") h = float(hrs) rate = input("enter the rate per hour: ") r = float(rate) if h >= 41: pay = (40r+(h-40)1.5r) else: pay = hr print(pay)

### ahmedsharifkhan commented Aug 17, 2020

 hrs = input("Enter Hours:") h = float(hrs) xx = input("Enter the Rate:") x = float(xx) if h <= 40: print( h * x) elif h > 40: print(40* x + (h-40)1.5x) Thank you so much

### bkonamo commented Aug 19, 2020 • edited

 hr1 = input('Enter Hour1: ') hr1 = float(hr1) hp1 = input('Enter Rate per Hour: ') if hr1 <= 40: print(float(hr1) * float(hp1)) elif hr1 >= 40: print(40 * float(hp1) + (float(hr1-40)) * 1.5* float(hp1))

### Ujjwal421 commented Aug 20, 2020

 Thank you so much

### Y123GOUTHAM commented Aug 20, 2020

 hrs = input("Enter Hours:") h = float(hrs) rate=input('Enter the rate per hour') r=float(rate) if h<=40: pay=hr print(pay) elif h>40: x=h%10 h=h-x pay=hr+x1.5r print(pay)

### gitpalashub commented Aug 21, 2020

 `sh = input("Enter Hours: ") sr = input("Enter Rate: ") fh = float(sh) fr = float(sr) if fh > 40: print("Overtime") reg = fr * fh otp = (fh - 40.0) * (fr * 0.5) print (reg,otp) xp = reg + otp else: print("Regular") xp = fh * fr print("Pay:",xp)` I have tried this code, and it works, it was taught by Chuck Severance. I did not understand why he used 0.5 in place of 1.5. can anyone explain?

### pedromrls commented Aug 21, 2020

 I have tried this code, and it works, it was taught by Chuck Severance. I did not understand why he used 0.5 in place of 1.5. can any Basically because you are adding 0.5 to the hours rate instead of 1.5, imagine it like this you make 10 per hr and every hour after 40 hrs a week is calculated as 0.5 times higher which on percentage would be that those hrs are paid 1.5x. Ex. you work 55 hrs, 10 rate, those 15 hrs are gonna be paid 0.5 times higher and you're gonna add up the result to the calculation, which would end up as 40 + 15 + 7.5 = 62.5 , times your rate which is 10 = 625 I don't know if my explanation makes sense but that's how I understood it after looking for the overtime rate in the US. So I would think that the way that the exercise is written is tricky and can be misunderstood.

### Shruti-Mishra77 commented Aug 25, 2020

 Why always showing bad input on line 7

### Ujjwal421 commented Aug 25, 2020

 xx = input('Enter no of hours') yy = int(xx) hh = input('Enter rate per hour') jj = float(hh) if yy <= 40: print(yy * jj) elif yy > 40: print(40*jj + (yy-40)1.5jj)

### Namstaxk commented Aug 26, 2020 • edited

 hrs = input("Enter Hours:") h = float(hrs) rate = input("Enter rate") r= float(rate) p=h x r pay=float(p) if h>40: pay=((h-40) x 1.5 x r + 40 x r) print(pay) Open for comments if any

### Imhsins commented Aug 26, 2020

 hrs = input("Enter Hours:") h = float(hrs) xx= input("Enter the rate:") x=float(xx) if h<=40: print(h_x) else: print(40_x+(h-40)_1.5_x) i am getting error in line 7 plz help. Indentation mistake

### gitpalashub commented Aug 27, 2020 • edited

 hrs = input("Enter Hours:") h = float(hrs) xx= input("Enter the rate:") x=float(xx) if h<=40: print(h_x) else: print(40_x+(h-40)_1.5_x) i am getting error in line 7 plz help. Indentation mistake #Imhsins , This is the correct code, try to run it. hrs = input("Enter Hours:") h = float(hrs) xx= input("Enter the rate:") x=float(xx) if h<=40: print(h*x) else: print((40*x)+(h-40)*1.5*x)

### suuuzana commented Sep 10, 2020

 TAHNXXXXXX <3

### gitpalashub commented Sep 10, 2020

 TAHNXXXXXX <3 Welcome.

### xjunio commented Sep 16, 2020

 hrs = input("Enter hrs: ") rate = input("enter rate: ") h = float(hrs) r = float(rate) if h <= 40: print(h * r) gross = 40 * r ext = h-40 pay = gross + ext*(1.5*r) if h>40: print(pay)

### Johnmanandhar13 commented Sep 23, 2020

 hrs=input("Enter Hours: ") hrs=float(hrs) hrly_rate=input("Hourly Rate: ") hrly_rate=float(hrly_rate) if hrs<=40 : x=print(hrly_rate) gross_pay=hrsx elif hrs>40 : y=print(40hrly_rate+(hrs-40)hrly_rate1.5) gross_pay=hrs*y print(gross_pay) questions cant we use else function? TypeError: unsupported operand type(s) for Mult: 'float' and 'NoneType' on line 10..i cant understand this error. IS SOMETHING WRONG WITH MY METHOD?

### xjunio commented Sep 23, 2020

 hrs=input("Enter Hours: ") hrs=float(hrs) hrly_rate=input("Hourly Rate: ") hrly_rate=float(hrly_rate) if hrs<=40 : x=print(hrly_rate) gross_pay=hrs_x elif hrs>40 : y=print(40_hrly_rate+(hrs-40)_hrly_rate_1.5) gross_pay=hrs*y print(gross_pay) questions cant we use else function? TypeError: unsupported operand type(s) for Mult: 'float' and 'NoneType' on line 10..i cant understand this error. IS SOMETHING WRONG WITH MY METHOD? please on line 10 you've already computed the gross_pay and placed in print function. Yes you can use the else function which you've already done but by default, you cannot multiply the hrs which is a float and y which is assigned to the print function. You will need to typecast or convert them to the appropriate data type before applying the operand. I have altered your code below and it is working perfect. see if this helps. thank you hrs=input("Enter Hours: ") hrs=float(hrs) hrly_rate=input("Hourly Rate: ") hrly_rate=float(hrly_rate) if hrs<=40 : x=hrs * hrly_rate gross_pay=x print(gross_pay) elif hrs>40 : y=(40*hrly_rate+(hrs-40)hrly_rate1.5) gross_pay=y print(gross_pay)

### adnankhan37 commented Sep 26, 2020 • edited

 Can anyone please help me out with this one? hrs = input("Enter Hours:") rate = input("Enter rate per hour:") h = float(hrs) r = float(rate) if h<=40: grosspay = r * h else: a = (h * r * 1.5) - (40 * r * 1.5) grosspay= (40* 10.50) +a print(grosspay) I am getting this dialogue box after running the code which says: "You must read the data using input() and then convert it." What is the reason behind it?

### xjunio commented Sep 26, 2020

 Can anyone please help me out with this one? hrs = input("Enter Hours:") rate = input("Enter rate per hour:") h = float(hrs) r = float(rate) if h<=40: grosspay = r * h else: a = (h * r * 1.5) - (40 * r * 1.5) grosspay= (40* 10.50) +a print(grosspay) I am getting this dialogue box after running the code which says: "You must read the data using input() and then convert it." What is the reason behind it? Hi please I have tested your code on Atom IDE and it is working perfectly with no errors. What editor are you using or the version of python installed ? I suggest you try another editor such as atom and try upgrade your python if possible. That might help thank you

### adnankhan37 commented Sep 27, 2020

 Can anyone please help me out with this one? hrs = input("Enter Hours:") rate = input("Enter rate per hour:") h = float(hrs) r = float(rate) if h<=40: grosspay = r * h else: a = (h * r * 1.5) - (40 * r * 1.5) grosspay= (40* 10.50) +a print(grosspay) I am getting this dialogue box after running the code which says: "You must read the data using input() and then convert it." What is the reason behind it? Hi please I have tested your code on Atom IDE and it is working perfectly with no errors. What editor are you using or the version of python installed ? I suggest you try another editor such as atom and try upgrade your python if possible. That might help thank you Hi, I am using Spyder (Python 3.7) and this code works perfectly on it. When I am running this code in the python autograder in the browser, then it shows the dialogue box with the message that I mentioned above earlier. Now I know why it is showing that message. The problem is that I have done hard-coding in line 11. Anyways thanks for your help. :)

### YashKavaiya commented Oct 9, 2020 • edited

 hrs = input("Enter Hours:") h = float(hrs) rate = input("Enter the Rate:") r = float(rate) if h <= 40: print( h * r) elif h > 40: print(40* r + (h-40)1.5r)

### ichthy0 commented Oct 11, 2020

 #This worked for me! hrs = input("Enter Hours:") h = float(hrs) xx = input('Enter Rate:') x = float(xx) if h <= 40: print(hx) elif h > 40: print(40 x + (h-40)x1.5)

### Govind12-uoh commented Oct 22, 2020

 Showing like this you must use a function called computepay to do the computation

### sourabh47512 commented Oct 24, 2020

 why h-40 Because it shows number of extra hours worked.

### eurjc commented Oct 27, 2020

 thank you!

### moemoe86 commented Nov 23, 2020

 Thank you!