...and Seek! in Battleship


#1

I got the following error for my code when I answered the prompts by typing in a number.

Traceback (most recent call last):
File "python", line 22, in
ValueError: invalid literal for int() with base 10: ''

(my 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)

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)

Add your code below!

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

PLEASE HELP


#2

if you enter numbers, this error message shouldn't occur. Can i see a screenshot of you entering numbers?


#3

Hi, stetim94!

Thank you for your prompt replay.
The following is the screen shot of my entering numbers.

Guess Row: 3
Guess Col:
Traceback (most recent call last):
File "python", line 23, in
ValueError: invalid literal for int() with base 10: ''

Nevertheless I clicked "Save & Submit Code" and typed a number, I can't sometimes see the number, on the screen, which I typed.
In a case my code doesn't have any error, I wonder that there are some errors in the system of Codeacademy.


#4

seems you didn't enter a number for guess col?

well, if you try to use int() without supplying a value which can be converted to integer, the python interpeter will give you an error.


#5

Stetim94

I entered a number and pushed the return key when I saw "Guess Col:" on the screen. However, the number didn't appear on the screen. Instead of that, there was the foregoing error message on the screen.
So, I think that it might be caused by the system problem.


#6

you have to enter numbers, codecademy can't fiddle with the python interpeter. You might want to click the terminal window you are typing in if the number doesn't show.

otherwise, try this:

while True:
    try:
        guess_row = int(raw_input("Guess Row: "))
        guess_col = int(raw_input("Guess Col: "))
    except ValueError:
         print "invalid"
    else:
         break

this will prompt until you enter valid values


#7

I succeeded to enter numbers and resolve this error by accessing Codecademy via windows PC.
(the error occurred in case of accessing it via Mac book.)

Thanks, stetim94!


#8