[Tutor] Input checking [letters or numbers]
Panagiotis Atmatzidis
p.atmatzidis at gmail.com
Fri Dec 23 20:28:47 CET 2005
On 12/23/05, Panagiotis Atmatzidis <p.atmatzidis at gmail.com> wrote:
> Hello Dany :-)
>
> On 12/23/05, Danny Yoo <dyoo at hkn.eecs.berkeley.edu> wrote:
[...]
> >
> >
> > Hello Bob and Panagiotis,
> >
> > It might be good to make this number-reading thing a function, just to
> > make it easier to reuse (and test!) it. Let's call this input_number()
> > for the moment.
> >
> > #######################################################
> > def input_number(prompt):
> > """Reads an integer from the next line of input."""
> > while 1:
> > x = raw_input(prompt)
> > if x.isdigit():
> > return int(x)
> > else:
> > print 'Boo'
> > #######################################################
[...]
> > I added one more behavior so that input_number continues to ask until it's
> > satisified by a number. Hope this helps!
>
> Yes, it really helps a lot. Now I can proceed with my script!!
[...]
Another newbe question! I use "while True: " to evaluate an
expression, I see that you used while 1: .. what's the diffrence if
any?!
--
Panagiotis
More information about the Tutor
mailing list