Where should I add this game over condition?

Question

Where should I add this game over condition?

Answer

We want to tell the user when the game is over regardless of why they guessed incorrectly on turn 4. If we put this new if statement inside of the existing else that handles misses, and directly after the if elif else blocks, then it will print at the correct times!
Your code should look something like the pseudo code below (pseudo code to avoid giving away 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”
    if last turn:  # THIS IS WHERE WE ADD IT
      print “Game Over”
    
    print current turn
    print the board

Pay close attention to the indentation above.

2 posts were split to a new topic: Did You Add Your if Statement With the “Game Over” Message?

Why did the if statement need to be in brackets? I don’t think I’ve seen this before so far?


  if (turn == 3):
      print "Game Over"

that shouldn’t be necessary.

1 Like