[Tutor] List exercise

Erik Price erikprice@mac.com
Fri Feb 7 07:54:01 2003


On Friday, February 7, 2003, at 07:30  AM, Anwar.Lorenzo@gmx.net wrote:

> just hangs when I execute this function.
>
> Here's my solution:
>
> def exerSize():
> 	exer = ['spam!', 1, ['Brie', 'Roquefort', 'Pol le Veq'], [1, 2, 3]]
> 	i = 0
> 	while i < len(exer):
> 		len(exer[i])
> 	i = i + 1

Hi Anwar,

I think the reason your program hangs is because you have an infinite 
loop.  The "while" loop says "while i is less than the length of exer", 
and since i is zero, this loop is always true, and never stops.  If you 
were thinking that your i variable would increment on each iteration of 
the loop (by using "i = i + 1"), the problem is that that line is 
outside of the loop.  So that line only executes after the loop is done 
iterating, but because it's an infinite loop, it never stops.

Try putting that i = i + 1 line inside the while loop and see what your 
program does.

while i < len(exer):
     len(exer[i])
     i = i + 1       # all you have to do is indent it to line up with 
the previous line



Erik





-- 
Erik Price

email: erikprice@mac.com
jabber: erikprice@jabber.org