Python Function Returning None

Solution 1:

Because in Python, every function returns a value, and None is what is returned if you don't explicitly specify something else.

What exactly did you expect print(printmult(30)) to do? You've asked it to evaluate printmult(30), and then print whatever results from that. Something has to result from it, right? Or were you maybe expecting some kind of exception to be raised?

Please be sure you understand that printing and returning are not the same thing.

Solution 2:

You are not returning anything in the function printmult, therefore when you print the result of printmult(30) it will be None (this is the default value returned when a function doesn't return anything explictly).

Since your method have a print statement inside and it's not supposed to return something (usually when a method names is something like printSomething(), it doesn't return anything), you should call it as:

printmult(30)

not

print(printmult(30))

Solution 3:

The other answers have done a good job of pointing out where the error is, i.e. you need to understand that printing and returning are not the same. If you want your function to return a value that you can then print or store in a variable, you want something like this:

def returnmult(n):
    i = 1
    result_string = ''
    while i <= 10:
        result_string += str(n * i) + ' '
        i += 1
    return result_string

print(returnmult(30))