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…