Python Forum

Full Version: Help with code
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm just trying out Python today and I tried to do some code and I got this error
print ("no")
myting = "hello world"
print = (myting)
mynem = input("What is your Name?")
myvar = input("I need a number :")

if(mynem == "Snek" and myvar != "0"):
	print("big vag")
elif(mynem == "majeff"):
        print("badjoke")
else:
	print("okgood")
Error:
Output:
Traceback (most recent call last): File "C:\Users\[my rl name]\Desktop\nonono.py", line 12, in <module> print("okgood") TypeError: 'str' object is not callable
I tried to look it up what that means but I don't understand it.
When using if and else statements the action has to be indented 4 spaces
change
print = (myting)
to

print(myting)
like this?

if(mynem == "Snek" and myvar != "0"):
print("big vag")
elif(mynem == "majeff"):
print("badjoke")
else:
print("okgood")

(ignore that)
Please use python and output tags when posting code and results. I put them in for you this time. Here are instructions for doing it yourself next time.

The problem is line 3. That assigns the string value 'hello world' to the name print, instead of printing it. Then, when you try to call the print function later, it is no longer a function, so it can't be called. I think you want to remove the equals (=) from line 3.