Python Program to Find Numbers Divisible by Number

« Previous Program Next Program »

Find Numbers Divisible by Number in Python

To find numbers divisible by another number in python, you have to ask from user to enter some sets of number say five numbers and then ask to enter a number to find the divisibility test and print the result on the output screen as shown in the program given below.

Python Programming Code to Find Numbers Divisible by Number

Following python program find numbers divisible by another number:

# Python Program - Find Numbers divisible by another number

print("Enter 'x' for exit.");
print("Enter any five numbers: ");
num1 = input();
if num1 == 'x':
    num2 = input();
    num3 = input();
    num4 = input();
    num5 = input();
    number1 = int(num1);
    number2 = int(num2);
    number3 = int(num3);
    number4 = int(num4);
    number5 = int(num5);
    numbers_list = [number1, number2, number3, number4, number5,];
    check_num = int(input("Enter a number to check divisibility test: "));
    res = list(filter(lambda x: (x % check_num == 0), numbers_list));
    print("Number divisible by",check_num,"are",res);

Here is the sample run of the above python program. This is the initial output asking from the user to enter any five numbers say a, b, c, d, e and then another number say x to find or fetch all the numbers from the list of entered five numbers that can be totally divided by the number x.

check divisibility test python

You can also skip or exit from the above program just by entering x as input. Now we are going to supply the values of five numbers, that is the value of a, b, c, d, e as 9, 15, 21, 34, 33 respectively and the value of x as 3 and then press enter to list out all the numbers from those 5 that are divisible by 3 as shown in the below screenshot:

find all numbers divisible by number python

Here is the same program on python shell:

python find numbers divisible by another number

Program Video with Compile and Run

« Previous Program Next Program »


Quick Links
Signup - Login - Give Online Test