This forum is now read-only. Please use our new forums! Go to forums
Can't figure out what the problem is
It is giving me a ‘NoneType’ object is not callable error and I can’t seem to figure out why that is. It was working find before but all of a sudden it just started having that error. Edit: So for some reason the system is not letting me cast the value i put in to a integer. Its giving the NoneType is not callable error and I am still pretty lost on why that is
from random import randint
board = []
for i in range(5):
board.append(["O"] *5)
print " ".join(board[i])
def battle_ship_location():
ship_row = randint(0, len(board) - 1)
ship_col = randint(0, len(board) - 1)
return ship_row, ship_col
def location_guess():
guess_row = int(raw_input("Enter row number"))
guess_col = int(raw_input("Enter col number"))
return guess_row, guess_col
def did_it_hit(gr, gc, sr, sc):
if gr == sr and gc == sc:
print "Congrats, you won"
return 1
elif (gr < 0 or gr > 4) or (gc < 0 or gc > 4):
print "Yo you way out there"
elif board[gr][gc] == "X":
print "Man come on you already shot there"
else:
print "Ha you missed!"
sr, sc = battle_ship_location()
for turn in range(4):
location_guess()
int = did_it_hit(gr, gc, sr, sc)
if int == 1:
break
Answer 5483dd1151b88764e6000773
you’re calling a value that is not callable. there’ll be a line number in the error message when you have the line you can add a print if you’re not sure which name is containing the non-callable value which you are trying to call. then look where it is coming from
NoneType is the type of the None object which represents a lack of value, for example, a function that does not explicitly return a value will return None
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
10 comments
I’m not sure what line that is since I have changed my code around a bit but it has to do with the guess_row = int(raw_input(“Enter row number”)) and then the next one. It allows me to run it once but once I go to put in mew values it hits me with that error
then read that error message for the line number
Traceback (most recent call last): File “python”, line 23, in
you know the line and you know that you are calling something not callable, look at the line. which names are you calling in that line? print them out, it should say that they are functions(or some other callable object), one of them will contain None
After printing it says they are callable objects, sorry if I’m not being the best at this still new to python and I’ve never come across this problem in any other languages
you are calling int. int contains None because you assigned the result of did_it_hit to it. when you start a python interpreter int refers to a class but you gave it a new value. don’t modify values of built-in names (usually called reserved names, but as you can tell not so much reserved in python), you can very much change them in python. it’s also a reason not to import names from other modules i.e. avoid from sys import * and instead do import sys and refer to those objects through sys
reserved* i’m clearly not properly awake
facepalm I completely forgot about that! Thank you so much wow ill make a note not to forget that again
figure out what made you miss it instead! it was perfectly possible to figure that int contained None. you can get pretty far with debugging with just prints, even if the language is new.. at the very least you can always narrow down what is causing it, where it no longer acts as you expect and that might be enough to google or look up some reference
Yea I was able to find out what piece of the code was causing the problem but even after looking it up i didn’t get much info. But i never made the connection that naming it the same as a built in object would cause the error. Bad programming on my part.