On 18/07/18 14:10, Matthew Polack wrote:
> Thanks for the reply Alan.
>
> I found another fix where I could just use this:
>
> num1 =int(input('Ener inches here?: '))
>
>
> but a lot of people like yourself.... seem to be recommending this
> 'float' method.

It all depends whether your input is a float or an integer.
If it will always be a whole number of inches then use int().
If it will be a floating point value then you need to use float().

In your example I'd have thought it reasonable to allow
conversions of, say, 11.5 inches...

I meant to add that its generally considered good practice
to do the conversion as early as possible unless you plan
on using the string version later. So wrapping the input()
call inside the int or float call is good.

You can then wrap that inside a try/except and get the user
to re-try if they type invalid data - if you so wish...


-- 
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@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to