CODING — Esercizio 3
📋 Testo
Exercise 3: Accumulated sum with limit 100
Write a program in Python that continuously takes integers as input and performs their accumulated sum.
The acquisition must stop as soon as the total sum of the numbers entered reaches or exceeds 100.
At the end, the program must print the total of the accumulated sum and the number of entries made.
Execution example:
Enter a number: 40
Enter a number: 35
Enter a number: 30
Reading interrupted! Final sum: 105, total entries: 3.
Analisi: The objective of the exercise is to teach the use of the accumulator and the counter within a conditional interruption cycle.
### Tutor Tips:
- Explain the use of a `sum` variable (initialized to 0) and a `count` variable (initialized to 0).
- Show how to set the loop condition `while sum < 100:` or control the sum internally within the loop.
### Common errors:
1. 'Off-by-one' error (e.g. not counting the last number that made it exceed 100).
2. Initialize the sum inside the loop, causing the accumulated value to be lost with each iteration.
3. Not updating the count variable correctly.