+ 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)

9th Jan 2020, 3:53 PM
Yash
Yash - avatar
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.
9th Jan 2020, 4:03 PM
A͢J
A͢J - avatar
+ 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)
9th Jan 2020, 4:01 PM
Preity
Preity - avatar
0
thanks, i forgot about the return statement
9th Jan 2020, 4:22 PM
Yash
Yash - avatar