Part of the series

Several example codes

~2 min read • Updated Oct 6, 2025

Program Overview

This Python program runs in a loop and reads integer values from the user.
- If the number contains the digit 0, it displays a warning message.
- If the number does not contain zero, it prints the number.
- To exit the program, the user must enter -1.


Python Code:


while True:
    num = int(input("Enter an integer (-1 to exit): "))
    
    if num == -1:
        print("Program terminated.")
        break

    if '0' in str(abs(num)):
        print("Warning: The number contains the digit zero.")
    else:
        print(f"Valid number: {num}")

Sample Output:


Enter an integer (-1 to exit): 27  
Valid number: 27  

Enter an integer (-1 to exit): 203  
Warning: The number contains the digit zero.

Enter an integer (-1 to exit): -1  
Program terminated.

Step-by-Step Explanation:

- The program runs in an infinite loop until -1 is entered
- Each number is converted to a string and checked for the digit 0
- If zero is found, a warning is printed
- Otherwise, the number is accepted and displayed


Written & researched by Dr. Shahin Siami