input – TypeError: int object is not callable in Python 3.2?

input – TypeError: int object is not callable in Python 3.2?

input() is a Python function, and you are using it both as the function and an identifier.

Using input as a variable name will work the first time, but the 2nd time through the loop there wont be an input() function any longer as that name now is associated with an integer variable.

So instead of function input() you just have a variable named input, hence the error (also as mentioned by @poke and @DSM in the comments)

Using answer as your variable name would be a better idea:

while True:
    answer = input(Select a spot:)
    answer = int(answer)

Youre using the name input for the result, which replaces the input function youre trying to call. Use a different name.

Edit: When you loop through, by the time the second iteration rolls around, you have rebound the variable input to your user input, so its not longer a builtin function, its the integer you just converted the user input to. The name input cant refer to two different things at the same time.

input – TypeError: int object is not callable in Python 3.2?

The first time you call

input(Select a spot:)

it works properly – returns a string, you convert it to int and store it to input.

The second time you call input, it takes the integer you just stored and tries to run it as a function. This fails, with the error message you have seen.

Leave a Reply

Your email address will not be published. Required fields are marked *