how to finish a while loop...

Guilherme Polo ggpolo at gmail.com
Tue Feb 19 20:10:22 EST 2008


2008/2/19, icarus <rsarpi at gmail.com>:
> Hi all, i'm new to python.  Learning on my own how to ask a user to
>  finish a loop or not.
>  For some reason, it behaves as infinite loop although I changed its
>  condition.  Please tell me what I'm doing wrong. Thanks in advance.
>
>
>  condition = True
>
>  while ( condition ):
>
>         try:
>                 integer_one = int ( raw_input( "Please enter an
>  integer: " ) )
>                 integer_two = int ( raw_input( "Please enter the
>  second integer: " ) )
>                 division = integer_one / integer_two
>
>         except( ZeroDivisionError ):
>                 print "\nDivision by zero detected"
>         except( ValueError ):
>                 print "\nYou didn't enter an integer"
>         else:
>                 print "The result is", division
>                 answer = raw_input("Do you want to try again (yes or
>  no)? ")
>                 if answer == 'yes':
>                         condition
>                 elif answer == 'no':
>                         condition = False
>
>  print "Good bye, you don't want to continue"
>
> --
>  http://mail.python.org/mailman/listinfo/python-list
>

That code works. Maybe you fixed it while you were mailing it =)

-- 
-- Guilherme H. Polo Goncalves



More information about the Python-list mailing list