Python Program to Find Numbers Divisible by Another Number – 2024

Hey guys, in this blog we will see a Python Program to Find Numbers Divisible by Another Number.

Code

# Python Program to Find Numbers Divisible by Another Number

# Take a list of numbers
my_list = list(map(int,input('Enter space seperated list of numbers: ').split()))
num = int(input("Enter number to check divisibility -> "))

# use lambda function to filter
result = list(filter(lambda x: (x % num == 0), my_list))

# display the result
print(f"Numbers divisible by {num} are",result)

Output

Enter space seperated list of numbers: 11 12 13 24 34 36 
Enter number to check divisibility -> 12
Numbers divisible by 12 are [12, 24, 36]
Enter space seperated list of numbers: 1 2 3 4 5 6 7 8 9 10
Enter number to check divisibility -> 2
Numbers divisible by 2 are [2, 4, 6, 8, 10]
Enter space seperated list of numbers: 1 2 3 4 5 6 7 8 9 10 11 12
Enter number to check divisibility -> 3
Numbers divisible by 3 are [3, 6, 9, 12]
  • This is a very simple program in which we are taking a list and a number as input from the user.
  • Then we are applying the lambda function to all the elements of the list.
  • And lastly filtering out all the numbers that returned 0 which means that they are purely divisible.

Check out our other python programming examples

Abhishek Sharma
Abhishek Sharma

Started my Data Science journey in my 2nd year of college and since then continuously into it because of the magical powers of ML and continuously doing projects in almost every domain of AI like ML, DL, CV, NLP.

Articles: 514

Leave a Reply

Your email address will not be published. Required fields are marked *