Function returns nothing rather than the expected value "None"

user4513674

I have no return put into my function, so I thought it should return "None". Instead, it simply does not return anything. Can someone tell me why? All help appreciated!

def posdivisor(n):
    for i in range(1,n+1):
        if n % i == 0:
            print(i)

someValue = eval(input("Enter an integer: "))

posdivisor(someValue)

THE SHELL REPORTS:

Enter an integer: 49
1
7
49
lqhcpsgbl

Because your code just print data, the function return a None, and you ignore it, try to print out will see None:

def posdivisor(n):
    for i in range(1,n+1):
        if n % i == 0:
            print(i)

someValue = eval(input("Enter an integer: "))

result = posdivisor(someValue)
print result

Besides, you don't need eval() here, just input() will be ok if you can insure that input is always number:

def posdivisor(n):
    for i in range(1,n+1):
        if n % i == 0:
            print(i)

someValue = input("Enter an integer: ")

result = posdivisor(someValue)
print result

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Graphite Returns All values, rather than function

.prop() returns object rather than value

pine-script function returns different value than expected

How to make a function which normally returns a value, return undefined rather than null when the value cannot be found

function outputting function text rather than expected output

getting dummy value in C++ code rather than expected value

Javascript: pass function by reference, rather than by value

Passing iterator value rather than reference to function

Python function returns None instead of int value when function is executed more than once

why the const function returns lvalue rather than rvalue?

How to get a function that returns an expression to be called rather than interpreted as an expression

Aggregate function (small) returns zeros rather than the smallest values

sizeof(struct) returns a SMALLER than expected value?

PHP array returns different value than expected

Why echo $? returns different value than expected?

Python recursive function returns None instead of value

Is there a way to compare two methods by function rather than value?

Function takes an argument literally rather than the value of the argument

Julia function return wrong value than expected

Function returns null instead of expected value

while loop returns a repeating random value rather than a new random value

split() in python3 not returning value as expected(spliting the whole string character wise rather than space wise)

python function returns nothing

Return function returns nothing

Haskell `sequence` function returns slightly different type than expected

Why LINQ returns other column value than expected?

children().count() of QGroupBox returns value more than expected

(() => {}) rather than the JavaScript function expression

My custom function returns the wrong thing rather than compiled string in Python