How should my code be indented inside of the new for loop?


#1

Question

How should my code be indented inside of the new for loop?

Answer

To ensure that we keep all of the same functionality per turn, just with the added ability to now take 4 turns before the game ends, we need to make sure we put everything we had before inside of the for loop we just created. The result should look like this (in pseudo code, to avoid giving the answer):

for turn in range(4):
  get guess_row
  get guess_col

  if guess is correct:
    print “Congrats! You sunk my ship.”
  else, not correct:
    if guess is invalid:
      print “Not in the ocean”
    elif already guessed:
      print “Already guessed!”
    else, just missed:
      print “Missed!”
      update element in board to be “X”
    print current turn
    print the board

Be sure to print the current turn + 1 like above as well!


FAQ: Learn Python - Battleship - Play It, Sam