Why my program returning ans with none. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why my program returning ans with none.

def function(celsius): celsius=float(input()) fahrenheit= 1.8 *celsius + 32 print(fahrenheit) print(function (36))

1st Nov 2020, 2:03 AM
Mudit Pandey
Mudit Pandey - avatar
4 Answers
+ 7
In Python any function or method that does not explicitly return a value will by default return None. Since function() does not explicitly return anything then None is returned from the call to function(). Try this instead; def func(celsius): return float(celsius) * 1.8 + 32 print(func(36))
1st Nov 2020, 3:43 AM
ChaoticDawg
ChaoticDawg - avatar
+ 5
Your function doesn't return any value to calling print function. So none will be printed
1st Nov 2020, 2:06 AM
Azhagesanヾ(✿)
Azhagesanヾ(✿) - avatar
+ 1
It is answering with "none" because you have no return value in your defined function. You have to do this. def function(): celsius=float(input()) fahrenheit= 1.8 *celsius + 32 return fahrenheit print(function()) https://code.sololearn.com/ciFuk1ozcV64/?ref=app
1st Nov 2020, 3:43 PM
Deep Kr. Ghosh
Deep Kr. Ghosh - avatar
+ 1
Ty it cleared my concept as well as my problem
3rd Nov 2020, 3:18 AM
Mudit Pandey
Mudit Pandey - avatar