Battleship

This lab was one of the longest and gave me more trouble. There was 3 different main sections to this lab.

1st: Don’t Sink My Battleship!

This section was actually not difficult it was very straight forward. For the first part all we had to do was create a variable named board and set it equal to an empty set.

image

Next we had to create a 5×5 grid stored in board by using range() to loop 5 times. Inside of these loop, we had to .append() a list containing 5 “0”s to board.

image

 

All we had to do here was use the print command to show the contents of the board listimage

This section we had to use ” ” as a separator to .join the elements

image

Here we had to print both the values of ship_col and ship_row

image

2nd: Hit or Miss?

We had to add an if guess_row equals ship_row and guess_col equals ship_col. Then, print out “Congratulations! You sank my battleship!”

image

Add a new if: statement that is nested under the else. With the example that was given, it should check to see if guess_row is not in range(5) or guess_col is not in range(5). If that is the case, print out”Oops, that’s not even in the ocean.”

image

3rd: You Sunk My Battleship!

During section 15: Play It, Sam, I got stuck and couldn’t go any further although, I followed all the steps in the instructions. image

All we had to do here was add a break under the win condition to end the loop after a win. This was easy.

image