Ask coding questions

← Back to all posts
Is not equal to wont work with if and elif
ThatBetaGuy (0)

So this code wont work

guess_row = input("Guess Row: ")
guess_col = input("Guess Col: ")
if guess_col == ship_col: 
  if guess_row == ship_row: #if the user input is correct then it will display "HIT"
    print("HIT")
  elif guess_col != ship_col or guess_row != ship_row: #if it is incorrect it will display "miss"
    print("miss")

I'm confused as to what i did wrong

Answered by Coder100 (18071) [earned 5 cycles]
View Answer
Comments
hotnewtop
Coder100 (18071)

it will be false because you are using the or statement
so that means
the x value and the y value must not be the same, not or.

Coder100 (18071)

here is a more efficient code:

if guess_col == ship_col and guess_row == ship_row:
  print("HIT")
else:
  print("MISS")