[Tutor] Issue with Code [SOLVED]
Alan Gauld
alan.gauld at yahoo.co.uk
Sun May 1 04:47:34 EDT 2016
On 01/05/16 05:20, Olaoluwa Thomas wrote:
> 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.
>
thanks :-)
> P.S. How were you able to open attachments with the restrictions on this
> mailing list?
The two code attachments made it to my reader.
But that seems to be a fairly arbitrary occurence.
The screen shot didn't make it.
Some make it, others don't. I don't know the exact
set of rules that determine when an attachment
gets through!
> 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))
You could have left it as else rather than elif,
but otherwise that's fine.
> I'm gonna add Try and Except to make it more responsive.
I'm not sure what you mean by responsive? The only
place try/except could/should be applied is round
the float conversions. But it only makes sense if
you put them inside a loop so you can force the
user to try again if the input is invalid.
Something like:
while True:
try:
value = float(input(...))
break
except ValueError:
print 'warning message....'
--
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
More information about the Tutor
mailing list