[Tutor] Issue with Code
Olaoluwa Thomas
thomasolaoluwa at gmail.com
Sat Apr 30 11:30:33 EDT 2016
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*
-------------- next part --------------
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))
-------------- next part --------------
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))
More information about the Tutor
mailing list