+ 1

why the output is always 0 ?

def print_nums(x): for i in range(x): print(i) return print_nums(10)

31st Aug 2016, 8:06 PM
Mouad Sama
Mouad Sama - avatar
4 odpowiedzi
+ 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 : )
31st Aug 2016, 8:21 PM
Mouad Sama
Mouad Sama - avatar
0
note the indent too tricky questions :-D answer : 0
12th Jun 2019, 2:38 AM
Mohammed Irfan Kasim
Mohammed Irfan Kasim - avatar
- 1
ans is 0
6th Apr 2018, 2:47 PM
Surya.R
- 2
answer is 0
18th Mar 2018, 4:47 PM
Amrish
Amrish - avatar