 # Why does the my code return none!? I’m a noob so I don’t know whether the question is overtly stupid or what😃

This returns none.
Ideal behind program is to convert Celsius to Fahrenheit using Fahrenheit = (9/5) * celsius + 32 But when I write return (9/5) * c + 32 it gives the desired result
Just curious on the difference between print ((9/5) * c + 32) and return

The value of the expression `conv(celcius)` is whatever you write after `return` in the `conv()` function. If there is no return statement, then a function defaults to returning `None`.

Consider the difference between these kinds of functions:

``````# A function that returns a value
# Doesn't "do" anything, only useful for what it returns
def square_of(x):
return x * x

# You can do stuff with the return value:
result = square_of(4)
print(result) # 16
print(result + 1) # 17

#################################################

# A function that "does stuff" rather than returning anything useful
def print_the_square_of(x):
print("Computing the square...")
square = x * x
print(square)
print("Finished computing the square.")
# No return statement is equivalent to "return None" here.

print_the_square_of(10) # the stuff happens when you call it
``````

The `print()` function is just another function, and it’s the kind of function that “does stuff” and returns `None` rather than returning anything useful.

Occasionally, a function will both “do stuff” (the term is side effects) and return a useful value:

``````def compute_cube(x):
print("Computing the cube...")
return x * x * x

cube = compute_cube(3) # prints "Computing the cube..."
print(cube) # prints 27
print(cube + 1) # prints 28
``````
1 Like

Hi Noel, and welcome!

In future, please don’t post screen shots of code, please copy and paste

You have two issues here.

When Python runs a function, when it gets to the very end of the
function and “falls off the end”, that’s the same as `return None`. So
by default, any function will return None unless you explicitly return
another value.

The other issue is that print is not return. `print` just prints the value
to the screen. To actually return a value, you must use `return`. Any
code after the `return` will not be run (because the function has
returned control to where it came from) and is called “dead code”.

Compare these two functions and see the difference in how they behave:

``````def demo1():
print("printing one")
print("and two")
print("and three")
return "done"

value = demo1()
print("The returned value is", value)

def demo2():
return "returning one"
return "and two"
return "and three"
print("done")

value = demo2()
print("The returned value is", value)``````
1 Like

Beautifully explained, thank you​:smiley:   Your help is much appreciated  Also, from next time on I will copy past my code, I didn’t knew this prior, sorry

Thank you for the clear explanation, much appreciated​:smiley:    This is for Steven as for some reason, I am not able to reply to your post