Danger, Will Robinson! invalid syntax with else statement?


#1


if guess_col == ship_col and guess_row == ship_row:
print "Congratulations! You sank my battleship!"
else: print "You missed my battleship!"

https://www.codecademy.com/courses/python-beginner-en-4XuFm/1/2?curriculum_id=4f89dab3d788890003000096#

I'm getting an 'incorrect syntax' message on the line with the else statement, and have no idea why. Thoughts?

Cheers :slight_smile:

EDIT - the indentation didn't come up. Both the 2nd and 3rd lines are indented. Sorry.


Replace this line with your code.


#2

if I'm not wrong, you indented both of these lines as you mentioned:
print "Congratulations! You sank my battleship!"
else: print "You missed my battleship!"

you're not supposed to have indented the "else" line because it goes as a pair with the "if" statement.


#3

Please post all your code


#4

mrsleepy - got it. Thanks for your help.

bandit - I'll be sure to do that next time. I'm still getting the hang of the system. Cheers for replying


#5

i think you didnt indent

also i found a mistake

after else: you need to enter statement in next line so it should look like

if guess_col == ship_col and guess_row == ship_row:
----print "Congratulations! You sank my battleship!"
else:
----print "You missed my battleship!"