Why is the output of this code: None 2 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
12th May 2020, 1:19 PM
Alen Antony
Alen Antony - avatar
7 Answers
+ 3
It will always return 1 in each condition. Here your fornication is acting just like a loop infact it is not a loop. by the way here result is 1 2
12th May 2020, 1:22 PM
Ayush Kumar
Ayush Kumar - avatar
+ 2
The correct format should be like this: def function(x): if x == 1: return x else: x -= 1 return x function(x) x = 2 print(function(x),x) Kindly upvote if it works for you. Thanks 😊
13th May 2020, 11:54 AM
Taofeeq Olawale Saad
+ 1
Try running the code you get output as : None 2
12th May 2020, 1:29 PM
Alen Antony
Alen Antony - avatar
+ 1
But when you run the code we get output as: None 2
12th May 2020, 1:32 PM
Alen Antony
Alen Antony - avatar
+ 1
Thanks ,I understood Can you upvote my question 😀
12th May 2020, 1:44 PM
Alen Antony
Alen Antony - avatar
20th Jul 2020, 1:10 PM
Namit Jain
Namit Jain - avatar
0
Second last line of your code has intendation, thus it is not a part of your function. As a result of which value of x is 2. And when yoy call a function outside of its defination it returns none.
12th May 2020, 2:39 PM
Mohd Gulam Ansari
  Mohd Gulam Ansari - avatar