Below code is printing None, but should be printing a value
num_ex = 3.5
def my_func(x):
if x >= 3.00:
x - 1
else:
x + 1
var_ex = my_func(num_ex)
print(var_ex)
Below code is printing None, but should be printing a value
num_ex = 3.5
def my_func(x):
if x >= 3.00:
x - 1
else:
x + 1
var_ex = my_func(num_ex)
print(var_ex)
Every Python user define function return None by default. You are not returning anything that's why it's returning None
To return a value from a function you use the return keyword.
Note: the return keyword terminates the function immediately when encounter.
For Example
num_ex = 3.5
def my_func(x):
if x >= 3.00:
return x - 1
return x + 1
var_ex = my_func(num_ex)
print(var_ex)