[Tutor] read from standard input
Tiger12506
keridee at jayco.net
Thu Feb 14 22:06:53 CET 2008
> while 1 < 2:
while 1:
or
while True:
is more common
> x = raw_input()
raw_input() always return a string, no matter what you type in.
> if type(x) != int or x == 11:
type(x) is always <type 'str'>
x can never be 11, but can possibly be '11'. (Notice quotes indicating
string instead of integer)
If you want an integer you must say
x = int(raw_input())
> break
> else:
> print x
> [/code]
>
> but don't work. and i'm interest in a general way to read until it is
> nothing to read.
>
>
> to ilustrate that in C:
> [code]
> int x;
> while( scanf("%d",&x) == 1 && x != 11)
> printf("%d\n", x);
> [/code]
>
>
> Thanks!
>
--------------------------------------------------------------------------------
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
More information about the Tutor
mailing list