Why is the output 0???? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
7th May 2020, 10:24 AM
Amanillah Mansuri
Amanillah Mansuri - avatar
20 Answers
+ 6
😀 that's true its output will be 0 because return statement is used to return some value when a function is called . But you hadn't writen anything in returne that means you are going to return nothing . Means a null value is returned . So compiler predicts null value as 0 because in binary format null stands for 0 . see the code of estifanos you will get it.
7th May 2020, 10:57 AM
Ayush Kumar
Ayush Kumar - avatar
+ 5
Yes Rithea Sreng I hadn't noticed the indentation of return. but in his code nothing is returned from a function because return statement dosent have any value . the 0 is just because of his print statement.
7th May 2020, 11:04 AM
Ayush Kumar
Ayush Kumar - avatar
+ 3
Remove the 'return' part def print_n(x): for i in range(x): print(i) print_n(10)
7th May 2020, 10:25 AM
estifanos
estifanos - avatar
+ 2
It will give you the output from 0 up to 9
7th May 2020, 10:28 AM
estifanos
estifanos - avatar
+ 2
for i in range(10) #it assigns the value of i from 0 up to 9 and check this out it might help you https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2434/ https://www.sololearn.com/learn/Python/2435/
7th May 2020, 10:37 AM
estifanos
estifanos - avatar
+ 2
You used the return statement, your loop ran once and the return statement brought the value which is 0 Your code should be like this def print_n(x): for i in range(x) print(i) def print_n(10)
8th May 2020, 6:17 PM
Gottem
Gottem - avatar
+ 2
when you use range(x) and x is 10, you want to go through all the values in a range from 0 to 9 the print(i) print the numbers in your range, but if your have a return, your code will print the first number i in your list and end the for. you need delete the 'return' to print all numbers in your range (10)
8th May 2020, 10:04 PM
Matheus Bonjour
Matheus Bonjour - avatar
+ 1
While you use return for def in for loop it returns only the first integer
9th May 2020, 3:44 AM
Jenson Y
0
And then
7th May 2020, 10:25 AM
Amanillah Mansuri
Amanillah Mansuri - avatar
0
Removing return is not doing any gud
7th May 2020, 10:28 AM
Amanillah Mansuri
Amanillah Mansuri - avatar
0
Infinte outputs
7th May 2020, 10:28 AM
Amanillah Mansuri
Amanillah Mansuri - avatar
0
But i want the output to be 0 but didn't get how the code is working
7th May 2020, 10:30 AM
Amanillah Mansuri
Amanillah Mansuri - avatar
0
Thanks
7th May 2020, 10:42 AM
Amanillah Mansuri
Amanillah Mansuri - avatar
0
Remove "return" that's all
8th May 2020, 5:07 AM
Anjan Kalita
Anjan Kalita - avatar
0
After the first iteration, the code hit return and return is keyword that executes and stop the code from executing further.
8th May 2020, 10:23 AM
Jibril Balogun
Jibril Balogun - avatar
0
Yes Rithea Sreng I hadn't noticed the indentation of return. but in his code nothing is returned from a function because return statement dosent have any value . the 0 is just because of his print statement.
8th May 2020, 12:58 PM
Nikhil Kulkarni
Nikhil Kulkarni - avatar
0
Sorry for being late with advice. The problem is contained in "return", it is not needed in the loop of this function
8th May 2020, 2:01 PM
Денис !
Денис ! - avatar
0
i see, its using return. yo used return, which might be used like print(my_thing()) not my_thing
8th May 2020, 3:38 PM
__ItzBrodieBoo__
__ItzBrodieBoo__ - avatar
0
You should remove the 'return' statement.
8th May 2020, 6:03 PM
THE APPRENTICE
THE APPRENTICE - avatar
0
Delete return.
8th May 2020, 6:10 PM
An Average Joe
An Average Joe - avatar