Raw_input not working


#1

I am currently up to the exercise of ‘Test Run’.

I can’t get through the exercise as I am unable to add anything into the ‘raw_input’ in the console. It isn’t allowing me to add any numbers to guess with, and it after a while it returns the error message:

Traceback (most recent call last):
File “python”, line 24, in
ValueError: invalid literal for int() with base 10: ‘SCT’

Can anyone let me know if there was anything wrong with my code, or whether it might be a computer problem instead.

My code looks like:



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

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


Could it be something after the initial ‘raw_input’ data that might be affecting it?

Thanks.


#2

raw_input is legacy Python. Try int(input("prompt")), and see if that fixes it. There doesn’t appear to be anything else wrong with the code.


#3

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