Sloppy example at sect 8.3 of Python 2.7.3 tutorial
Hi, At http://docs.python.org/release/2.7.3/tutorial/errors.html sect 8.3, the first example block should ask the user for an "integer", not just a "number". I happily entered 1.23 without thikning too much and it failed. There you go ! One Giant Leap ..... -- Greg Edwards, Port Jackson Bioinformatics gedwards2@gmail.com
Hello Greg, thanks for your email. On Sat, Jun 23, 2012 at 11:51 PM, Greg Edwards <gedwards2@gmail.com> wrote:
Hi,
At http://docs.python.org/release/2.7.3/tutorial/errors.html sect 8.3, the first example block should ask the user for an "integer", not just a "number". I happily entered 1.23 without thikning too much and it failed.
If you enter 1.23 you've just tested the except branch:
while True: ... try: ... x = int(raw_input("Please enter a number: ")) ... break ... except ValueError: ... print "Oops! That was no valid number. Try again..." ... Please enter a number: 1.23 Oops! That was no valid number. Try again... Please enter a number:
As far as I can see, the example works as expected, and there's nothing wrong with it (not even the imprecise indication of what number to enter). Cheers, -- Sandro Tosi (aka morph, morpheus, matrixhasu) My website: http://matrixhasu.altervista.org/ Me at Debian: http://wiki.debian.org/SandroTosi
participants (2)
-
Greg Edwards
-
Sandro Tosi