0
Why is the output 0????
20 Respuestas
+ 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.
+ 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.
+ 3
Remove the 'return' part
def print_n(x):
for i in range(x):
print(i)
print_n(10)
+ 2
It will give you the output from 0 up to 9
+ 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/
+ 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)
+ 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)
+ 1
While you use return for def in for loop it returns only the first integer
0
And then
0
Removing return is not doing any gud
0
Infinte outputs
0
But i want the output to be 0 but didn't get how the code is working
0
Thanks
0
Remove "return" that's all
0
After the first iteration, the code hit return and return is keyword that executes and stop the code from executing further.
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.
0
Sorry for being late with advice. The problem is contained in "return", it is not needed in the loop of this function
0
i see, its using return.
yo used return, which might be used like
print(my_thing())
not
my_thing
0
You should remove the 'return' statement.
0
Delete return.