Issues with Code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

30th May 2021, 3:42 PM
Arazi David
Arazi David - avatar
5 Answers
+ 5
this code add from 0 untill (function input)-1
30th May 2021, 3:54 PM
aspad🇮🇷
aspad🇮🇷 - avatar
+ 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
30th May 2021, 3:48 PM
TOLUENE
TOLUENE - avatar
+ 1
Arazi David Did you try to run the code in the playground? Which part of the code confuses you?
30th May 2021, 3:47 PM
Denise Roßberg
Denise Roßberg - avatar
0
Run the code to see the output. However due to improper indentation the code will ofcourse throw few errors
30th May 2021, 3:48 PM
Abhay
Abhay - avatar
0
Thank you ...6 is correct
30th May 2021, 3:53 PM
Arazi David
Arazi David - avatar