For loop including enumerate method(Python)
a = [2, 4, 6, 8] sum = 0 for p, n in enumerate(a, 2): sum += p print(sum) Output: 14 So I just played challenge here and now confused by that code. First of all, why is there a second element n? How does it affect this? I already found out that it doesn't really matter what is in the list (wether there are strings, interegers or floats), but the amount of them affect the result. If there was one more item in the list, the output would be 20. By the way, if I remove the n element, it returns the TypeError. Also how the enumerate() function works here, is very unusual to me. I didn't find any similar examples to that. When I tried to remove it, it returned ValueError: too many values to unpack (expected 2). I'll be happy for your respond. https://code.sololearn.com/c6xK0s6XK2n2/?ref=app