Can someone explain to me what's wrong with this code? The output should be 20. Sorry for any inconvenience | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can someone explain to me what's wrong with this code? The output should be 20. Sorry for any inconvenience

https://code.sololearn.com/cZLKp32m46kH/?ref=app

27th Feb 2019, 4:57 AM
thariq
thariq - avatar
2 Answers
+ 2
Total is initially items[0] which is 3, and in for loop you revisit that 3 again, that's where 23 comes from, instead of 20... Just say total=0 instead of items[0]
27th Feb 2019, 5:05 AM
Elva
Elva - avatar
+ 2
Thanks, it worked :)
27th Feb 2019, 6:22 AM
thariq
thariq - avatar