Error help TypeError: 'int' object is not callable

Hello, I am completely new to the coding world, and so far have completed 11% of python. I am working on the magic8ball project. I am stuck and need help with the error TypeError: ‘int’ object is not callable .
My full code is

import random

random_number = random.randint(1, 9)

print = (random_number)

name_magic = “Lee”

question = “Should I eat pizza today?”

magic_8balls_answer= “answer”

answer = “”

if random_number == 1:

answer = “Yes-definitely.”

elif random_number == 2:

answer= “It is decidedly so.”

elif random_number == 3:

answert = “Without a doubt.”

elif random_number == 4:

answert = “reply hazy, try again.”

elif random_number == 5:

answert = “Ask again later.”

elif random_number == 6:

answert = “Better not tell you yet.”

elif random_number == 7:

answert = “My sources say no.”

elif random_number == 8:

answert = “Outlook not so good.”

elif random_number == 9:

answert = “Very doubtful.”


answert = “Error.”

print(name_magic + “asks:” + question)

print("Magic 8-Ball’s answer: " + answer)

Please use backticks for your code to show indentations etc


Hello @core9679598999, welcome to the forums! Your issue stems from the fact that in Python, there are built in functions. The print() function is one of them-it logs something to the console. To print something, you simply type print("something you want to print").

What you’ve done is type print = (random_number), which actually creates a variable called print. This variable stores the integer value stored in random_number.

The print() function is now overridden, which basically means writing print() doesn’t actually call the built-in function print(); it tries to use the variable you created as a function. Since you’ve only stored an integer value in your print variable, you can’t use that as a function (like here for example):

Which then throws the error. You can read more about your error message here.

Completely unrelated to your error, but you may want to look at the spelling of answer in your elif and else blocks:

elif random_number == 3:

answert = “Without a doubt.”

what a silly mistake, thank you

1 Like

ok, I will try that, thank you for the reply