Battleship Code


#1



Hello All, Please help me withn the below code.

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


Oops, try again. It looks like the rows are not represented as lists.


['O', 'O', 'O', 'O', 'O']
['O', 'O', 'O', 'O', 'O']
['O', 'O', 'O', 'O', 'O']
['O', 'O', 'O', 'O', 'O']
['O', 'O', 'O', 'O', 'O']


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


#2

@abhiaiem:

board.append("O") #at the end you'll have just a big list
board.append(["O"]) #at the end you'll have a list inside another list

That's all! :sunny:


#3

The list inside the list also should have 5 "O"

so, first make a list containing 5 "O" by multiplying it with 5, then append it into board list.

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

print board

#4

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