[Tutor] python help

Alan Gauld alan.gauld at yahoo.co.uk
Sat Sep 12 16:46:53 EDT 2020


On 12/09/2020 18:56, John Weller wrote:

> ...the way to check if a number is an integer is:
> 
> If number == int(number):
> 	Print("Integer")
> Else:
> 	Print("Not integer")

Sorry, tat won;t work. int() will throw an exception if it can't convert
the argument so it needs to be:

try: int(...)
except ValueError: ...

-- 
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