FAQ: Learn Python - Battleship - Custom Print

This community-built FAQ covers the “Custom Print” exercise in Codecademy’s lessons on Python.

FAQs for the Codecademy Python exercise Custom Print:

Join the Discussion. We Want to Hear From You!

Have a new question or can answer someone else’s? Reply (reply) to an existing thread!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources about Python in general? Go here!

Want to take the conversation in a totally different direction? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account, billing, Pro, or Pro Intensive? Reach out to our support team!

None of the above? Find out where to ask other questions here!

Other FAQs

The following are links to additional questions that our community has asked about this exercise:

  • This list will contain other frequently asked questions that aren’t quite as popular as the ones above.
  • Currently there have not been enough questions asked and answered about this exercise to populate this FAQ section.
  • This FAQ is built and maintained by you, the Codecademy community – help yourself and other learners like you by contributing!

Not seeing your question? It may still have been asked before – try (search) in the top-right of this page. Still can’t find it? Ask it below by hitting the reply button below this post (reply).

4 posts were split to a new topic: Why Do These prints Not Work?

the parameter was never used. the solution relied on using the global variable “board”

board = []

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

def print_board(board_in):
  for row in board:
    print row

In the for loop, how does the computer just know what “row” is when it’s not like “board[row]” to select something within the “board” list

python can give use the values from the list directly, which is what is happening here. So, we could loop over the list and request the indexes and then use these indexes to get the values from the list, but why would we if python can do that for us?

This is my question also … how does python just know what “row” is. I don’t understand the guest moderator answer. Is row a function in Python that I forgot we learned earlier? When we appended to the list Board, it didn’t seem to me that python was organizing the data into rows at all, hence the output that was NOT in a 5x5 grid the first time we printed it.

row is nothing special. Its just a variable. But given we defined/named this variable in a loop, python will now assign each element of the list to this variable