+ 1
could someone explain why the highest number this code outputs is 0
def print_nums(x): for i in range(x): print(i) return print_nums(10)
3 Respuestas
+ 5
Because you returned after printing the first value. So it will break the loop and you get 0 because first index of iteration is 0.
+ 1
Yash return statement is return only single value after the function end so you need to call function again for next value. In your code after returning 0 function call end so didnt return other range number Just remove return statement.
def print_nums(x):
for i in range(x):
print(i)
print_nums(10)
0
thanks, i forgot about the return statement