Error!


#1

Hi! I keep having this error:

“O O O O O
O O O O O
O O O O O
O O O O O
O O O O O
2
0
Guess Row: Traceback (most recent call last):
File “python”, line 25, in
ValueError: invalid literal for int() with base 10: ‘SCT’”

I think it’s a bug, because i’ve checked and the code is alright. It seems to happen when i use a “raw_input” sentence. The problem is that i cannot go on to the next exercise. Here is the code:

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)

print_board(board)

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"```

#2

This error excludes us since it is a problem with the lesson checker, the Submission Correctness Test.

If this is the lesson I think it is, the workaround is to comment out those two lines and write the input values directly.

guess_row = ship_row
guess_col = ship_col

The values are arbitrary, but I just chose two that existed in the environment.

Not sure there are any other lessons with this issue. Let us know if you run into similar problems as you go. You can use this thread as a ping target.


#3

Hi! Thx to answer so fast. Well, i have advanced a little and now i get the same problem at exercise 11/19:

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

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)

print_board(board)

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)
guess_row = int(raw_input("Guess Row: "))
guess_col = int(raw_input("Guess Col: "))

print ship_row
print ship_col

# Write your code below!
if guess_row == ship_row and guess_col == ship_col:
  print "Congratulations! You sank my battleship!"
  
else: "You missed my battleship"
guess_row = "X"
guess_col = "X"

The code isn’t right, i was trying to see the error but only that SCT problem appears.


#4

Also evidence of an internal problem we cannot resolve on this side, only work around it. Try the same trick. If your debugging lines are removed, just use any pair of values that are each in range(5). [0, 1, 2, 3, 4]


#5

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