3. Make a List


#1


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

"Oops, try again. It looks like you do not have 5 rows in your list."

Exactly what did happen. 5 rows. Is using range really necessary or is Codeacademy really only allowing one way to solve this?


board = []

board_grid = 0

while board_grid < 5:
    print ['O'] * 5
    board_grid = board_grid + 1


Results are:

['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']
None


#2

i don't think range is needed (i have to try, but it must be possible), but you will need to append your rows to your board array, not print the rows, if you only print the rows, they aren't stored, which becomes a problem later on


#3

Thanks for the explanation about storage. After getting the result I showed here, did what they wanted and everything was fine. Just needed to know why.


#4

well think about it for a second, the code you had in the original question, would only print the board, but not store it. Then how would you know if your ship has been hit? Or not hit? If you store it in a array (multi-dimensional array) you could update the array to indicate a hit or a miss (and check if the user entered something valid)

Does that answer all your questions?


#5

Sure thing, even if the player guessed the correct space, that code would still print a grid of O's.


#6

Yes, exacxtly. you undestand it