0

How the answer become 6? Explain please

https://code.sololearn.com/c4deX7bIhqCZ/?ref=app

30th May 2021, 3:11 PM
Sooraj K Sunu
Sooraj K Sunu - avatar
2 Réponses
+ 4
Sooraj K Sunu Your program should look like this with proper indentation. def func(x): res = 0 for i in range(x): res += i return res print(func(4)) -------- Explanation: we have defined a function and passed 4 as a parameter. Now in that function we have loop with range (x) for x = 4, range (4) will return list [0, 1, 2, 3] And we are adding this list values using loop so here output is 0 + 1 + 2 + 3 = 6
30th May 2021, 3:26 PM
A͢J
A͢J - avatar
0
Your indentation in improper. Better write the code in code playground and share its link here.
30th May 2021, 3:16 PM
Arsenic
Arsenic - avatar