ValueError: invalid literal for int() with base 10: 'SCT'



<Below this line, add a link to the EXACT exercise that you are stuck at.>

<In what way does your code behave incorrectly? Include ALL error messages.>

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

<What do you expect to happen instead?>
I should expect that this game would work smoothly. I dont understand the error.


from random import randint

board = []

for x in range(0, 5):
board.append([“O”] * 5)

def print_board(board):
for row in board:
print " ".join(row)


def random_row(board):
return randint(0, len(board) - 1)

def random_col(board):
return randint(0, len(board[0]) - 1)

ship_row = random_row(board)
ship_col = random_col(board)
print ship_row
print ship_col
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!"
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."
print "You missed my battleship!"
board[guess_row][guess_col] = "X"

<do not remove the three backticks above>


When raw_input is called… Do you input a value other than an int? That will often be the cause of this issue. You cannot cast object of type str to type int unless the str object contains ONLY an int value.


This presents as a glitch in the SCT. For this exercise, comment out the input statements and assign values to your variables manually. The same may apply to other lessons with this same issue.


I saw other replies before you guys replied and I found out that the soultion that @mtf has suggested here works and there is indeed some glitch. So, no i didn’t enter any values other than int and moreover, it shows error even before feeding in any input!


Thanks @mtf. I read other comments saying the same thing and it worked. Hope people could fix this issue.


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