def random_row(board, length):
return randint(0, len(board) - length)
def random_col(board, length):
return randint(0, len(board[0]) - length)
ship_all = []
for length in range(1,6):
ship = []
ship_row = random_row(board, length)
ship.append(ship_row)
ship_col = random_col(board, length)
ship.append(ship_col)
i = 0
if randint(0,1) == 0:
while i<length:
ship_all.append(ship)
ship[0] += 1
print ship
i+=1
else:
while i<length:
ship_all.append(ship)
ship[1] += 1
print ship
i+=1
print ship_all
The ship_all.append(ship) just give the final result of the ship, but print ship works out correctly, how to solve this problem?