+ 1
Issues with Code
def func(x) res = 0 for i in range (x) res + = i return res Print (func(4)) Please what is the outcome
5 Respostas
+ 5
this code add from 0 untill (function input)-1
+ 3
Explanation :
for i in range(4):
res += i
1st loop: res = 0+0
2nd loop : res = 0+1
3rd : res = 1+2
4th : res = 3+3 = 6
Final value of res (6) is the output
+ 1
Arazi David
Did you try to run the code in the playground?
Which part of the code confuses you?
0
Run the code to see the output.
However due to improper indentation the code will ofcourse throw few errors
0
Thank you ...6 is correct