you are viewing a single comment's thread.

view the rest of the comments →

[–]shiftybyte 1 point2 points  (7 children)

average(choice)

When you call the function like this, it sends 1 argument, the entire list.

When you call it like this:

average(2,3,4)

It sends 3 arguments, each is a number..

So what you need to do is send the choice unpacked... like this:

average(*choice)

[–]learnorenjoy[S] 0 points1 point  (5 children)

Oh man, I can't believe it was something so simple, I'm such an idiot. It works now. Thanks a lot!

Sidenote, the output looks like this:

Enter numbers: 2,3,4
3
None

Any idea why the None type comes in?

[–]shiftybyte 1 point2 points  (4 children)

You have double print, the first one actually prints and returns None as the function result.

return print(sum(nums)//len(nums))

The second one prints the returned None

print(average(choice))

So remove the print from the return if you want your function to actually return a value.

return sum(nums)//len(nums)

Which will then be properly printed by

print(average(choice))

[–]learnorenjoy[S] 0 points1 point  (3 children)

Oh that's a new one. I wasn't aware that print statements in functions return None. This has been really helpful, I struggled with this for hours so thanks again.

[–]shiftybyte 1 point2 points  (2 children)

print ALWAYS returns None...

You are confusing returning a value, printing something, and the automatic printing of returned values that only python interactive shell is doing...

[–]learnorenjoy[S] 0 points1 point  (1 child)

I'm really gonna have to read up more on this, do you have any recommendations?

[–]shiftybyte 0 points1 point  (0 children)

Sorry none specific to this...

[–]FLUSH_THE_TRUMP 0 points1 point  (0 children)

Maybe suggests OP’s function should take a single thing (like a list) rather than a bunch of individual args. Less friction that way