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

CODING — Esercizio 2b

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

📋 Testo

Exercise 2b: Interruption on consecutive double zeros


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


The acquisition of numbers must end only when the user enters the number 0 twice in a row.


At the end of execution, the program must communicate that the sequence has ended due to the double zero inserted.



Execution example:


Enter a number: 3
Enter a number: 0
Enter a number: 7
Enter a number: 0
Enter a number: 0
Reading interrupted: zero entered twice consecutively!

Analisi: This exercise is a variation of the previous exercise but focused on a specific value (0). It can be solved by storing the previous state or by keeping a counter of consecutive zeros.

### Tutor Tips:
- Help the student implement the logic either through the comparison `current == 0 and previous == 0` or through a counter of consecutive zeros that resets if a value other than 0 is entered.
- Emphasize that a single 0 should not interrupt execution.

### Common errors:
1. Stop the cycle at the first 0 entered.
2. Do not reset the counter of consecutive zeros if a different number is entered after a zero (e.g. the sequence 0, 5, 0 would cause a shutdown if the counter does not reset).

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