First day beginner to python, add to counter after nested loop

Dave Angel davea at davea.name
Tue Oct 29 15:24:57 EDT 2013


On 29/10/2013 14:35, jonas.thornvall at gmail.com wrote:

(Deleting hundreds of quad-spaced garbage.  Please be more considerate
of others if you choose to use buggy googlegroups, maybe starting by
studying:

)

Please indent by 4 columns, not 1.  Since indentation is how scope is
specified in Python, it's very important to get it right.

> i do not understand howto reach outer loop after finnish inner loop, in fact i do not understand when finished.

The inner loop is finished whenever you stop indenting by 8 columns.  If
you have a fundamental problem like this, keep it simple till you
understand it:


q = 12
for x in range(10):
    for y in range(3):
        q = 3*q + 1
        print("inner", q)
    print("outer", x*q)

print("done")

Because of the detenting, the print("outer", x*q) is in the outer loop.


-- 
DaveA





More information about the Python-list mailing list