Hi I'm new to programming. I tried to use for loop and a nested while loop to calculate the sum of an arithmetic sequence on condition that the sum is no bigger than 100. I wrote the code below, but the output was 100 instead of the correct sum of the elements of the sequence (which should be 92).
# Arithmetic sequence
ele = 1
diff = 3
arithmetic_sequence = []
while ele < 60:
arithmetic_sequence.append(ele)
ele += diff
print(arithmetic_sequence)
#[output: [1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 34, 37, 40, 43, 46, 49, 52, 55, 58]]
# Sum of the arithmetic sequence -- the output is 100, very weird
sum_arithmetic = 0
for ele_f in arithmetic_sequence:
while sum_arithmetic < 100:
sum_arithmetic += ele_f
print(sum_arithmetic)
#[output: 100]
Could anyone help me check what went wrong in my code? Thank you in advance!