-1

I have a piece of code that should be printing a number. But it instead prints "None", along with the number I anticipated it to print. Here is the snippet of code that should produce, at the very last line, just the number 3.

mylist=[]
def number_replied(user):
    for z in task1dict:
        if user in task1dict[z]:
            mylist.append(z) 

def how_many_replied_to(username):
    del(mylist[:])
    number_replied(username)
    print(len(mylist))

print(how_many_replied_to('joeclarkphd'))

This should produce the result, "3", but it shows "None", a line break, "3". Is there something I need to add or change? Let me know if you need more of the code.

  • 2
    change the print(len(mylist)) to `return len(mylist)` Your function currently returns None by default since you don't have a return statement – Garrett R Mar 02 '16 at 22:02
  • Duplicate of http://stackoverflow.com/questions/34404947/my-function-returns-none – Prune Mar 02 '16 at 22:14

2 Answers2

0

Functions return None unless they have a return something_that_is_not_none statement that gets executed in the function's body.

You are printing the value in the function, returning None and then printing that return value in the caller.

mgilson
  • 300,191
  • 65
  • 633
  • 696
0

Following up on the previous answer, change the last line of the second function from print(len(mylist)) to return len(mylist) and you're good to go.

Magneto
  • 93
  • 7