Learn
Battleship!
Printing Pretty

We’re getting pretty close to a playable board, but wouldn’t it be nice to get rid of those quote marks and commas? We’re storing our data as a list, but the player doesn’t need to know that!

letters = ['a', 'b', 'c', 'd'] print " ".join(letters) print "---".join(letters)
  1. In the example above, we create a list called letters.
  2. Then, we print a b c d. The .join method uses the string to combine the items in the list.
  3. Finally, we print a---b---c---d. We are calling the .join function on the "---" string.

We want to turn each row into "O O O O O".

Instructions

1.

Inside your function, inside your for loop, use " " as the separator to .join the elements of each row.

Folder Icon

Take this course for free

Already have an account?