Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

I tells me line 1 and line 5 (new to debugging/programming, not sure if that helps)

def hi():

print 'hi' 

def loop(f, n):

if n<=0: 

return 

else:

f() 

loop(f, n-1) 

loop(hi(), 5) 

hi 

TypeError: 'NoneType' object is not callable

Why does it give me that error?

1 Answer

0 votes
by (106k points)

You want to pass the function object hi to your loop() function, not the result of a call to hi() (which is None since hi() doesn't return anything).

You can try this:

>>> loop(hi, 5) 

hi 

hi 

hi 

hi 

hi

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...