Home The Project Blog Plans Mission
Login Register
Home
CODING Es. 6 Pag. 1

CODING — Esercizio 6

🎓
You are exploring a public demo
Sign up to access all exercises and save your progress.
Sign up for free →

📋 Testo

Exercise 6: Sum of odd numbers with limit 10


Write a program in Python that prompts the user for continuous integer input.


The program must accumulate the sum of only the odd numbers entered. Insertion must stop as soon as this sum of odd numbers reaches or exceeds the value of 10.


Note: even numbers entered by the user must be read and accepted, but must not contribute to the sum of the odd ones and do not affect the interruption.


When finished, print the sum of the odd numbers obtained and the list of odd numbers that determined it (or their count).



Execution example:


Enter a number: 3
Enter a number: 8
Enter a number: 5
Enter a number: 6
Enter a number: 3
Reading interrupted! Sum of odd numbers: 11 (3 + 5 + 3). Even numbers entered were ignored for the purpose of the sum.

Analisi: This exercise requires the use of a conditional control structure nested inside a loop (an `if` inside a `while`), since only some of the numbers entered (those that satisfy the condition of being odd) change the state of the accumulator.

### Tutor Tips:
- Help the student identify odd numbers using `n % 2 != 0` or `n % 2 == 1`.
- Explain that even numbers must still be read but not added.
- Show how to keep track of only the odd ones by accumulating them in a dedicated variable.

### Common errors:
1. Add all the numbers entered without distinction.
2. Stop the loop when an even number is entered.
3. Not incrementing the amount correctly.

Your Solution Reflection Code
▶ Write your solution-reflection and send it for a guided review.
Socratic AI Tutor
TUTOR AI

Contact us for a free trial