def func(x) res=0 for i in range(x): res+=i return res print(func(4)) how is answer is 6. after running the code line by line, wont return res terminate the loop and return value 0 to print? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

def func(x) res=0 for i in range(x): res+=i return res print(func(4)) how is answer is 6. after running the code line by line, wont return res terminate the loop and return value 0 to print?

2nd Aug 2016, 5:40 AM
Roshan Maharjan
Roshan Maharjan - avatar
4 Answers
0
#first you need to put colon after func ":" def func(x): res=0 for i in range(x): res+=i #dont use "return" , you need to see resalt, use "print" hear print(res) #and then you need just call the func func(4)
2nd Aug 2016, 6:23 AM
Pavel
Pavel - avatar
0
jk
9th Nov 2018, 5:42 PM
Noah cox
0
def g(m,n): res = 0 while m >= n: (res,m) = (res+1,m/n) return(res)
2nd Feb 2020, 5:29 PM
Mayur Roy
Mayur Roy - avatar
- 1
I get the same return of 0. I am not understanding where 6 fits in.
6th Mar 2018, 6:56 PM
Stan Smoczyk
Stan Smoczyk - avatar