Jan-07-2019, 08:39 AM
Pages: 1 2
Jan-07-2019, 12:12 PM
Yes sorry micseydel is right, I overread that part. rate should be an input as well
The correct code is:
The correct code is:
hours = float(input("Enter hours: ")) rate = float(input("Enter rate per hour: ")) ratePlus = rate * 1.5 if hours > 40: pay = 40 * rate + (hours - 40) * ratePlus else: pay = hours * rate print (pay)
Jan-07-2019, 02:22 PM
(Jan-07-2019, 12:12 PM)Mr_W Wrote: [ -> ]Yes sorry micseydel is right, I overread that part. rate should be an input as well
The correct code is:
hours = float(input("Enter hours: ")) rate = float(input("Enter rate per hour: ")) ratePlus = rate * 1.5 if hours > 40: pay = 40 * rate + (hours - 40) * ratePlus else: pay = hours * rate print (pay)
thank you my friend
It worked
(Jan-07-2019, 02:22 PM)ramadan2099 Wrote: [ -> ](Jan-07-2019, 12:12 PM)Mr_W Wrote: [ -> ]Yes sorry micseydel is right, I overread that part. rate should be an input as well
The correct code is:
hours = float(input("Enter hours: ")) rate = float(input("Enter rate per hour: ")) ratePlus = rate * 1.5 if hours > 40: pay = 40 * rate + (hours - 40) * ratePlus else: pay = hours * rate print (pay)
thank you my friend
It worked
whats wrong in my code here
[Image: 284945816.png]
Jan-07-2019, 06:14 PM
ramadan2099: it sounds like that's a different question, please start a new thread. Also, as I've said more than once, stop posting screenshots, start using code tags, start providing errors (are you getting a syntax error? it looks like it).
Jan-07-2019, 07:31 PM
(Jan-07-2019, 06:14 PM)micseydel Wrote: [ -> ]ramadan2099: it sounds like that's a different question, please start a new thread. Also, as I've said more than once, stop posting screenshots, start using code tags, start providing errors (are you getting a syntax error? it looks like it).
I am sorry
thanks
Apr-27-2020, 05:43 PM
Hello all
I see that a working codehas already been posted but I'm trying to resist just copying somebody else's work. However, I'm getting a headache staring at this now!
I'm a total beginner, admittedly but it's frustrating me that I'm getting stumped so early on in this course.
With the below code, I'm not getting any errors, it's a perfectly good, working code.
The issue is that I should be able to input:
Hours 45 (sth)
Rate 10.50 (str)
...and come out with an answer of 498.75
My code is coming up with 551.25 !
I'm sure it's something really simply that I'm overlooking because I've been staring for too long but can anyone spot it?
I see that a working codehas already been posted but I'm trying to resist just copying somebody else's work. However, I'm getting a headache staring at this now!
I'm a total beginner, admittedly but it's frustrating me that I'm getting stumped so early on in this course.
With the below code, I'm not getting any errors, it's a perfectly good, working code.
The issue is that I should be able to input:
Hours 45 (sth)
Rate 10.50 (str)
...and come out with an answer of 498.75
My code is coming up with 551.25 !
I'm sure it's something really simply that I'm overlooking because I've been staring for too long but can anyone spot it?
sth = input("Enter hours: ") str = input("Enter rate: ") flh = float(sth) flr = float(str) if flh > 40 : reg = flr * flh ot = (flh - 40.0) * (flr * 1.5) pay = reg + ot else: pay = flh * flr print (pay)
Apr-27-2020, 06:57 PM
You are paying 2.5 times for overtime.
You are not alone. I fall into the same trap at times and when I eventually step away from the computer and look at what I was doing I am appalled. The most important lesson I could teach you is that programming is a multi-part task. The first, and most important element is design, and that should occur away from the computer.
if hours > 40: pay = hours * rate # paid for overtime at regular rate overtime = (hours -40) * rate * 1.5 # and more pay for overtime at 1.5 * rateThis is not a programming error and has nothing to do with python. This is a logic error. I think you are too worried about how to solve your problem in python when you should instead be focusing on how to solve the problem and then implementing your solution in python.
You are not alone. I fall into the same trap at times and when I eventually step away from the computer and look at what I was doing I am appalled. The most important lesson I could teach you is that programming is a multi-part task. The first, and most important element is design, and that should occur away from the computer.
Apr-27-2020, 08:01 PM
(Apr-27-2020, 06:57 PM)deanhystad Wrote: [ -> ]You are paying 2.5 times for overtime.
This is not a programming error and has nothing to do with python. This is a logic error. I think you are too worried about how to solve your problem in python when you should instead be focusing on how to solve the problem and then implementing your solution in python.
You are not alone. I fall into the same trap at times and when I eventually step away from the computer and look at what I was doing I am appalled. The most important lesson I could teach you is that programming is a multi-part task. The first, and most important element is design, and that should occur away from the computer.
I thought as much! Thank you.
Appreciate the tips as well, I’ll bear them in mind.
Jan-23-2021, 06:27 AM
use
print('pay=')
print(pay)
print('pay=')
print(pay)
Pages: 1 2