Add It Up โ
What is 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10?
Don't do it in your head โ make Python do it. ๐งฎ
The pattern is a running total: a variable that starts at 0 and grows every time round the loop.
total = 0
for number in range(1, 4):
total = total + number
print(total) # โ 6 (that's 1 + 2 + 3)
Remember range(1, 4) gives 1, 2, 3 โ it stops before the second
number. Sneaky! ๐
Your mission
Add up every number from 1 to 10 with a loop, then print the total.
(No typing the answer. I'll know. ๐)
Your code
Press โถ Run to see what your code does!