Where should I add this game over condition?
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.