0

How is the output accumulated?

Could you please explain me this code? Why the output is not simply func(5)+func(4)=3+2? Thank you very much! https://code.sololearn.com/cREVZs0T5ux5/?ref=app

27th Jan 2020, 4:34 PM
Nemui
7 Antworten
+ 4
Arr remains alive after the first call and we have: Arr = [0,2,4]=>len = 3 #first call Arr = [0,2,4,0,2]=>len = 5 second call So first + second = 3+5=8
27th Jan 2020, 4:45 PM
Qasem
+ 3
Ok lets do job sharing: You hack the code into SL coding section and I will tekk u. In general a linked code has better chances for supoort.
27th Jan 2020, 4:43 PM
Oma Falk
Oma Falk - avatar
+ 3
The idea is still the same as I mentioned: [0,2,4] #len = 3 =>line1 [0,2,4,0,2] #len = 5 =>line2 [0,2,4,0,2,0,2,4] #len=8# + [0,2,4,0,2,0,2,4,0,2] #len=10 => len=8+10=18 =>line3. And for line4 it's same.
28th Jan 2020, 2:01 PM
Qasem
+ 1
Oma Falk noted with thanks! I’m sorry for that, the code is added.
28th Jan 2020, 12:39 PM
Nemui
+ 1
Qasem oh i see! I changed ‘return len(arr)’ to ‘return arr’ and got your general idea. Thanks a lot. However, if it returns len(arr), func(range(5))+func(range(4)) gives 18? But if it returns arr, there are 20 values in the array.
28th Jan 2020, 12:44 PM
Nemui
+ 1
Qasem ohh okok, thanks for your patience to explain me the details!
28th Jan 2020, 2:27 PM
Nemui
0
Nemui great!
28th Jan 2020, 12:40 PM
Oma Falk
Oma Falk - avatar