Hi All,
I sent this forwarded email earlier but hadn't subscribed to the mailing
list so I guess that's why I didn't get a response.
Please review and advise.
*Warm regards,*
*Olaoluwa O. Thomas,*
*+2347068392705*
---------- Forwarded message ----------
From: Olaoluwa Thomas <thomasolaol...@gmail.com>
Date: Sat, Apr 30, 2016 at 4:30 PM
Subject: Issue with Code
To: tutor@python.org
Hi, I'm new to Python and programming in general. I came across a simple
exercise that is used to compute gross pay when prompted to enter number of
hours and hourly rate.
I've attached the scripts in question (created via Notepad++).
The 1st script I wrote worked perfectly.
The 2nd script makes amendments to the 1st by increasing the hourly rate by
50% when number of hours is greater than 40.
The problem with this script is that the "else" statement (which is
equivalent to the 1st script) does not compute gross pay accurately as seen
in the attached screenshot.
I would appreciate a logical explanation for why the "else" statement in
the 2nd script isn't working properly.
I'm running Python v2.7.8 on a Windows 7 Ultimate VM via Command prompt and
my scripts are created and edited via Notepad++ v6.7.3
*Warm regards,*
*Olaoluwa O. Thomas,*
*+2347068392705*
hours = raw_input ('How many hours do you work?\n')
rate = raw_input ('What is your hourly rate?\n')
gross = float(hours) * float(rate)
print "Your Gross pay is "+str(round(gross, 4))
hours = raw_input ('How many hours do you work?\n')
rate = raw_input ('What is your hourly rate?\n')
if hours > 40:
gross = ((float(hours) - 40) * (float(rate) * 1.5)) + (40 * float(rate))
else:
gross = float(hours) * float(rate)
print "Your Gross pay is "+str(round(gross, 4))
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor