[Tutor] Programming Question

naoki inada inadauer at gmail.com
Tue Sep 19 16:20:44 CEST 2006


> How do I get it to work after an incorrect number is
> entered?  I am stuck on this and would appreciate and
> help or suggestions?

Use exception

>>> try:
...   int("hoge")
... except(ValueError):
...   print('incorrect')
...
incorrect


> elif number == 1:
>     print "One"
> elif number == 2:
>     print "Two"
> elif ...

Using table is more smart way.

NUMBER_STRINGS = ['Zero', 'One', 'Two', 'Three', ...]
print NUMBER_STRINGS[number]


More information about the Tutor mailing list