Make a list


#1



https://www.codecademy.com/courses/python-beginner-en-4XuFm/0/3?curriculum_id=4f89dab3d788890003000096#


Getting error: Oops, try again. Your code looks a bit off. Check the Hint if you need help! Your code threw the following error: 'return' outside function (python, line 5)


board = []
for O in range(0,5):
    print ["O"] * 5
    board.append(O)
return board
print board


#2

Instruction says this..

Inside the loop, .append() a list containing 5 "O"s to board, just like in the example above

two lines of code..

print ["O"] * 5
board.append(O)

hint**
Instruction have not asked to print ["O"] * 5
It asked to append ["O"] * 5 to board ?


#3

Not to mention I didn't need a return statement...


#4

Exactly,as you'd have seen this message (Error : return statement outside of function)

(reading theory+ following instruction solves more than half of the problem..last part remains is to find a logic to accomplish the final part of problem.)


#5

you can try this Code is Work:
board = []
for i in range(0,5):
lists = ["O"] * 5
board.append(lists)
print board


#6

Hi! try this code:

board=[]

for i in range(0,5):
board.append(["O"]*5)
print board

  1. You dont need to return the statement as the error have shown :slight_smile:
  2. ["O"] * 5 put it together as an board.append, as you need to "append" the board list with the Os since its a empty list.

Hope it helps! :slight_smile:


#7

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