Battleship 3. Make a list clarification Q


#1


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

My code works, but I have a confusion.
1) If I want 5 "O", why I am specifying a range(0,5)? Isn't range (start, stop noninclusive)? Shouldn't I input a range (6) to indicate I want a range of 5?

2) After the code to loop, I specify I want the board appended with "O" 5 times. Where am I telling the code that I want 5x5?

board = []

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

print board

#2

no? 0,1,2,3,4 are 5 numbers, so should be good?

well here:

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

you append ["O","O","O","O","O"], and you do this 5 times thanks to your for loop. 5 * 5 makes 25


#3

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