dioretsa
dioretsa

Reputation: 65

python error "typeerror: nonetype object not callable"

I'm trying to make a simple timer script in python. I see a lot of other people have had this error too, but I think my error may be different because I'm new to python:

time=60
from time import sleep
while (time>0):
    print ("you have") (time) ("seconds left")
    time-=1
    sleep(1)

below is the result:

>>> you have Traceback (most recent call last): File "H:\counter.py", line 4, in <module> print ("you have") (time) ("seconds left") TypeError: 'NoneType' object is not callable

Can anyone spot this error? using %s has also failed me along with using +'s and str() around the time variable

Upvotes: 0

Views: 12497

Answers (2)

Quirk
Quirk

Reputation: 1337

You are using the wrong syntax for the print function. Please note that print in is a callable. So when you call it, you can pass all that you need to be printed as parameters.

Hence

print ("you have", time, "seconds left")

is the correct syntax. You can optionally also specify a separator.


For posterity, TypeError: 'NoneType' object is not callable is an error thrown when you try to use an NoneType object as a callable. Python flagged out when it discovered that you had tried to pass time (an object) to print ("you have") which returns a NoneType object.

Remember, in print is a callable and it essentially returns a NullType object (which is nothing at all for that matter, and hence not callable).

Upvotes: 2

Aswin Murugesh
Aswin Murugesh

Reputation: 11070

A function can have only a single set of arguments.

print_statement = "you have" + str(time) + "seconds left"
print(print_statement)

The above code should work.

Upvotes: 3

Related Questions