0

Can Any one tell me why it is getting error, if we put "print" in place of "return"?

def lang(ext): if ext == ".py": return "Python" elif ext == ".js": return "JavaScript" elif ext == ".html": return "HTML" elif ext == ".css": return "CSS" elif ext == ".c": return "C" else: print("enter valid extention: ") print("The Extention You Entered Is "+ lang(input("Enter An Extention: \n")))

16th Jul 2020, 10:06 AM
Mr. 12
Mr. 12 - avatar
7 Respuestas
+ 6
When the function call doesn't reach any return statements it returns None instead. The error was raised by a concatenation with string and None.
16th Jul 2020, 10:09 AM
Seb TheS
Seb TheS - avatar
+ 3
This is what causes the error: "The Extension You Entered Is " + None
16th Jul 2020, 10:13 AM
Seb TheS
Seb TheS - avatar
+ 3
Mr. 12 Yes, it would fix the error.
16th Jul 2020, 10:14 AM
Seb TheS
Seb TheS - avatar
+ 1
Mr. 12 Another thing you need to understand about return is that it won't go further down if the return condition is met. For example: def test(num): if num == 3: return True print("yes") print (test(3)) Output: True yes won't print because return acts like break in a loop Hope you understand 😃😃
16th Jul 2020, 10:11 AM
Tomiwa Joseph
Tomiwa Joseph - avatar
+ 1
Seb TheS thank you bro.
16th Jul 2020, 10:15 AM
Mr. 12
Mr. 12 - avatar
0
Seb TheS can u please explain briefly
16th Jul 2020, 10:11 AM
Mr. 12
Mr. 12 - avatar
0
Seb TheS you are saying that, we hvae to convert the input into string! right?
16th Jul 2020, 10:14 AM
Mr. 12
Mr. 12 - avatar