Lab Description:

This lab consist  of implementing functions, built-in functions, methods, modules, lists and the for loop to create a game called “Battleship”. I import the random module in order to use the randint later on in the program. I also created a list where a loop was used to create 5 sub-list inside the list. Something new that I learn in this lab is that you can use a function and for loop to print the sub-list vertically and also remove the “[]” (line 10) form the list. We used the randint to produce a random integer from 0 to 4 (the length of the list, which is 5, minus 1) to place the ship in a combination a row and column. The random integers were placed for the variables ship_row (with value of the random row) and for the variable ship_col (with value of the random column), can be found on lines 14 – 21. Then, the variables guess_row and guess_col were set with the value int(raw_input(‘Guess Row: “)) and int(raw_input(‘Guess Col: “)) to allow the user to input the number that she or he is guessing of the row and column where the ship is located. if, elif and else statements were created to guide the user if the numbers that were entered close to the ship, or miss the ship, or hit the ship. As shown in step 3, lines 43-44, another for loop was used to created turns to allow 4 chances for the user to play before the Game Over.

Step #1:

 

 

 

Step #2:

 

 

 

Step #3:

 

 

 

Step #4:

 

 

 

Step #5:

 

 

 

Step #6: