0
How the answer become 6? Explain please
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
0
Your indentation in improper. Better write the code in code playground and share its link here.