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

CODING — Esercizio 2

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

📋 Testo

Exercise 2: Interruption upon insertion of two identical consecutive numbers


Write a program in Python that prompts the user for a sequence of integers.


The program must continue to read input numbers and must stop immediately when the user enters the same exact number twice in a row.


At the end of execution, the program must print a closing message indicating what the repeated number is.



Execution example:


Enter a number: 12
Enter a number: 4
Enter a number: 5
Enter a number: 5
Reading interrupted: the number 5 has been entered twice consecutively!

Analisi: This exercise introduces the student to the concept of state management between iterations of a loop. The student must memorize the value entered in the previous iteration to be able to compare it with the current one.

### Tutor Tips:
- Suggest the student read a first number before starting the cycle, in order to have an initial comparison value ('previous').
- Show how to update the previous number variable at the end of each iteration: `previous = current`.

### Common errors:
1. Initialize the 'previous' number variable with a fixed value (e.g. 0), which could erroneously cause the loop to end if the user types 0 immediately.
2. Compare the variable with itself within the same loop without updating its state correctly.
3. Mishandling the first 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