Python Forum
Python for Everybody 3.1 assignment
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python for Everybody 3.1 assignment
#11
I will try
Reply
#12
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)
Reply
#13
(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]
Reply
#14
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).
Reply
#15
(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
Reply
#16
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?

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)
Reply
#17
You are paying 2.5 times for overtime.
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 * rate
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.
Reply
#18
(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.
Reply
#19
use
print('pay=')
print(pay)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python for Everybody 5.2 assignment baba04201 20 172,670 Jul-25-2023, 04:15 PM
Last Post: MicaelSchutz
  Coursera python for everybody 5.2 assignment SteppentigerV2 11 12,710 Oct-22-2020, 11:57 AM
Last Post: Larz60+
  [split] Python for Everybody 5.2 assignment ramadan2099 3 11,981 Jul-15-2020, 04:54 PM
Last Post: Bipasha
  Python Assignment 3 - Applied Data Science - 2.3 eyavuz21 8 4,885 Jun-06-2020, 08:59 AM
Last Post: eyavuz21
  Python Password Saver Assignment sshellzr21 2 6,104 May-02-2020, 01:34 AM
Last Post: sshellzr21
  Python for Everybody 3.3 assignment ramadan2099 7 31,643 Apr-08-2020, 06:49 AM
Last Post: DeaD_EyE
  Python for everyone course assignment 5.2 ofekx 3 8,482 Dec-23-2019, 08:41 PM
Last Post: nilamo
  [split] Python for Everybody 5.2 assignment jonchanzw 4 8,404 Oct-22-2019, 08:08 AM
Last Post: perfringo
  Python Assignment 5.2 amos76823 3 15,917 Jan-17-2019, 07:34 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020