+ 1
why the output is always 0 ?
def print_nums(x): for i in range(x): print(i) return print_nums(10)
4 Respuestas
+ 5
thank you i figured out the answer :
well its because of the intended space in return
as you can see the return has the same space as print(i) ,in this case python will only print the first number in the range which is 0
but if we changed the code and returned the intended space of " returne " in the same space as "for loop " the program will return all the numbers in the range you chose :
def print_nums(x):
for i in range(x):
print(i)
return
print_nums(10)
hope everyone enjoyed the lesson : )
0
note the indent too
tricky questions :-D
answer : 0
- 1
ans is 0
- 2
answer is 0