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

CODING — Esercizio 1

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

📋 Testo

Exercise 1: Interruption on an even number


Write a program in Python that continuously reads as input a sequence of integers supplied by the user.


The program must stop reading as soon as the user enters an even number.


When finished, the application should display a message indicating that reading was interrupted due to the entry of an even number, and also display that number.



Execution example:


Enter a number: 5
Enter a number: 13
Enter a number: 7
Enter a number: 8
Reading interrupted: you have entered the even number 8!

Analisi: The objective of this exercise is to verify the student's ability to implement conditional break loops (while loops) or indefinite loops with break statements.

### Tutor Tips:
- Guide the student to understand how to test whether a number is even using the modulus operator `%` (i.e. `n % 2 == 0`).
- Explain the difference between a `while True:` loop with an internal `break` construct and a loop controlled directly by a sentinel or boolean variable (e.g. `pari_trovato = False`).

### Common errors to monitor:
1. Incorrect use of the form (e.g. `n % 2 == 1` to identify even numbers).
2. Infinite loops due to failure to read new input within the loop body.
3. Type-Errors caused by forgetting to convert the input from string to integer via `int(input(...))`.

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