Confused on extra output in display


#1



The first block of code I tried ran and I couldn't pass. I think it's because "n" was referenced in the for loop, but changing the variables in the for i loop resulted in errors and for some reason the extra number of 2.
After checking the hint I passed but I don't know where that extra number in the display came from or why my first attempt didn't work properly.


#Displays 3, 5, 7, 2
n = [3, 5, 7]
for i in range(0, len(n)):
    print n[i]
def print_list(x):
    print i
print print_list(n)

#Working code stuffs, displays 3, 5, 7

n = [3, 5, 7]
def print_list(x):
    for i in range(0, len(x)):
        print x[i]
print print_list(n)


#2

The first example is definitely not right. The last value to be stored in i is 2 and that's what prints when the line print i executes.


#3

I thought that by printing i the function would reference the for loop named i.

So then where is i assigned the value 2?


#4

When the for loop executed, it started with i = 0, then 1, and finally 2. Incremting stopped at 2 and the value is still in i.


#5

So it was reference the i loop! Just not in the way I expected, thank you.