Problem with raw_input (Battleships)


#1

Hi!
I have a problem with the raw_input function. I call it two times, to write the row and the column, but it seems to work just one time. It did work during previous steps and I didn’t change anything in the code, but now it just lets me put only one number.

guess_row = int(raw_input("Guess Row: "))
guess_col = int(raw_input("Guess Col: "))


if guess_row==ship_row and guess_col==ship_col:
  print("Congratulations! You sank my battleship!")
elif board[guess_row][guess_col]=="X":
  print("You guessed that one already")
else:
  if guess_row not in range(5) or guess_col not in range(5):
    print("Oops, that's not even in the ocean.")
  else:
    print("You missed my battleship!")
    board[guess_row][guess_col]="X"
    print_board(board)
  

This is the part where it stops working correctly. It looks like this on the console:
image

Anyone had similar problem?


#2

It must have had a number from somewhere or it’d crash when attempting to convert the col to integer

This would be codecademy’s fault, perhaps if you’re lucky reloading “fixes” it, otherwise you could skip taking input and write those values directly in the code instead


#3

I reloaded the page and it worked, thank you :slight_smile:


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.