A for loop that adds all 4-digit even numbers one after another, printing the intermediate sum for every 100th number (i.e., at the index positions 99, 199, 299, ...) along with its index number. Here is my answer so far:
l = range(1, 1000, 2)
sum1 = 0
for i in range(len(l)):
sum1 += l[i]
if i % 100 == 99 and (len(l[i]) == 4):
print(sum1, i)
print(sum1)
Here's the error I'm getting:
TypeError Traceback (most recent call last) <ipython-input-175-6ae4f990101a> in <module> 4 for i in range(len(l)): 5 sum1 += l[i] ----> 6 if i % 100 == 99 and (len(l[i]) == 4): 7 print(sum1, i) 8 TypeError: object of type 'int' has no len()
Can anyone enlighten me of what I am doing wrong? Any help will be appreciated. Thanks!