[Tutor] Issue with Code [SOLVED]

Olaoluwa Thomas thomasolaoluwa at gmail.com
Sun May 1 00:20:23 EDT 2016


Thank you so much, Alan. That fixed it (See Script 2[SOLVED] below).

For the purpose of record-keeping, I'm pasting the entire code of all
scripts below as I should have done from the very beginning.

P.S. How were you able to open attachments with the restrictions on this
mailing list?

Script 1
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))

Script 2
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))
elif hours >= 0 and hours <= 40:
    gross = float(hours) * float(rate)
print "Your Gross pay is "+str(round(gross, 4))

Script 2 [SOLVED]
hours = float(raw_input ('How many hours do you work?\n'))
rate = float(raw_input ('What is your hourly rate?\n'))
if hours > 40:
    gross = ((hours - 40) * (rate * 1.5)) + (40 * rate)
elif hours >= 0 and hours <= 40:
    gross = hours * rate
print "Your Gross pay is "+str(round(gross, 4))

I'm gonna add Try and Except to make it more responsive.

Thanks a lot!

*Warm regards,*

*Olaoluwa O. Thomas,*
*+2347068392705*

On Sun, May 1, 2016 at 2:00 AM, Alan Gauld via Tutor <tutor at python.org>
wrote:

> On 01/05/16 01:16, Alan Gauld via Tutor wrote:
>
> > I can't see anything obviously wrong in your code
>
> I was too busy focusing on the calculations that
> I didn't check the 'if' test closely enough.
> You need to convert your values from strings
> before comparing them.
>
> hours = float(raw_input ('How many hours do you work?\n'))
> rate = float(raw_input ('What is your hourly rate?\n'))
> if hours > 40:
>    gross = (hours-40)*(rate*1.5) + (rate*40)
> else:
>    gross = hours*rate
>
>
> Sorry,
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list