Part of the series

Several example codes

~1 min read • Updated Oct 13, 2025

Program Overview

This Python program reads an integer n and displays all numbers from 1 to n that are divisible by 7 and do not contain the digit 7.
It uses two separate methods: one to check divisibility and another to check digit presence.


Python Code:


def is_multiple_of_7(num: int) -> bool:
    return num % 7 == 0

def contains_digit_7(num: int) -> bool:
    while num > 0:
        if num % 10 == 7:
            return True
        num //= 10
    return False

def display_valid_numbers(n: int):
    for i in range(1, n + 1):
        if is_multiple_of_7(i) and not contains_digit_7(i):
            print(i)

# Read input from user
n = int(input("Enter value for n: "))
print(f"Multiples of 7 without digit 7 up to {n}:")
display_valid_numbers(n)

Sample Output (input: n = 101):


7 skipped (contains digit 7)  
14  
21  
28 skipped  
...  
98  

Written & researched by Dr. Shahin Siami