Fun with Blocks Exercises


Instructions: Create a new notebook called Battleship in your FunWithBlocks directory and follow the instructions below to convert it to a visual game with the aid of ipythonblocks.

Preliminaries: At the top of your notebook, include a "Heading 1" cell with the title Battleship. Then include the inline functions and libraries you need by adding a code cell that invokes the %pylab inline magic and imports the needed packages.


  1. Open Codecademy and grab your Battleship! code from Lesson 13-18.
  2. Copy it to a new notebook called Battleship in your FunWithBlocks directory and use ipythonblocks to make it more visual.
    • Use a light blue for the background, red for a hit and a different color of your choice for misses.
  3. Once it is working:
    • Expand it to a larger field
    • Make the battleship longer
    • Provide more tries for the player to find it and completely sink it.
    • If the player doesn't sink the ship before the end of the game, reveal the playing board to them so they can see where it was.
  4. Document your code with a markdown cell that explains how to run it and what the options are.
  5. Demonstrate the game in another cell to show that it works as expected. You do not have to provide a demo for each possible outcome. Just one demo will do.
  6. Get creative. You could allow ships to lie diagonally, make the player say how many tries they would like to use to sink it, add more ships, etc.

Your output for this exercise will be graded. Your code must implement the elements listed in items 1-5 above. You will also receive a creativity bonus for any additional features that the code implements (such as those suggested in item 6 or others you come up with). Be sure to document the extra features too!

Note: ipythonblocks may show up again on the midterm...


All content is under a modified MIT License, and can be freely used and adapted. See the full license text here.