Reference to the same row


Oops, try again. It looks like your board has 5 references to the same row! This will cause problems later on. Read the hint for more information and use a for loop to complete this lesson

I expect the code to run with out errors
What is the reference error and waht problems would be caused later?

Replace this line with your code. 
board = []

row = ['O']*5

for i in range(5):
    i = row
    print i
print board


well, row is a list


i = row

this will not create a copy of a list, this varaible will just reference to the row list

so you are appending the same list 5 times to board

which means, that if we where to update a missed guess with X, this would happen in every row instead of just one row


ok. Thanks for the reply.
But is there any other way in which the variable i creates a new copy of the list instead of referring to it.


i would do what the exercise recommends, simply append ['O']*5 to board, this will create a new list every time


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.