This forum is now read-only. Please use our new forums! Go to forums
ValueError: invalid literal for int() with base 10: ''
Hello guys,I met a problem,here is the whole 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:") )
when I submit and enter a number,the console says: Traceback (most recent call last): File “python”, line 22, in
what happened?I really appreciate if you can tell me the right answer!
Answer 52b447f69c4e9d0775002492
Answer 52b496a480ff339b61000023
you can convert an empty string to an int, that’s what the error is saying (ValueError: invalid literal for int() with base 10: ''
)
be sure to format code in your post correctly, indentation matters
![1]
highlight all the code and then click the {}
-button (or Ctrl + K)
[1]: http://i.imgur.com/FZyPDjY.png
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency
4 comments
thank you,but I don’t quite get it.Do you mean”you can’t convert” by “you can convert”? Please forgive my poor English.
can’t*, yeah. sorry
thank you.But it’s not empty.I do enter a number.So the conclusion is : the raw_input() function didn’t work.I tested in the console,I wrote: guess_row = raw_input(“Guess Row:”) print guess_row then I submitted,entered a number,but it printed nothing: Guess Row:
Guess Col: None I tried again in the terminal of my ubuntu system,it was ok—-got printed.I don’t know what to do now
you could press enter you should be able to enter numbers too :S i might have tried a different browser, or just do the exercises with raw_input in your local python environment - you don’t really need it to check you - you can always judge your code by its behavior. you could also try to use input instead of raw_input, don’t convert it to int though, it will already be - input reads input as if it were python code