The "loop and a half"

Thomas Jollans tjol at tjol.eu
Tue Oct 3 14:20:44 EDT 2017


On 03/10/17 20:05, Dennis Lee Bieber wrote:
>
> while True:
> 	x = input("Enter a number (blank to exit) => ")
> 	if x:
> 		try:
> 			ix = int(x)
> 			print("Square = %s" % (ix * ix) ) #why invoke exponential
> 		except checkTheDocsForException:

The nice thing about how the stdlib does exceptions is that you can be
pretty certain that this has simply got to be a ValueError. It's still
best to check (or, in this case, try it out) - but you just know that
there's nothing else it can be.

> 			print(" '%s' is not a valid integer" % x )
> 	else:
> 		break


PS: I was weak. I tried it out before sending this mail.





More information about the Python-list mailing list