Python Program to Find Numbers Divisible by Another Number

To understand this example, you should have the knowledge of the following Python programming topics:


In the program below, we have used anonymous (lambda) function inside the filter() built-in function to find all the numbers divisible by 13 in the list.

Source Code

 # Take a list of numbers my_list = [12, 65, 54, 39, 102, 339, 221,] # use anonymous function to filter result = list(filter(lambda x: (x % 13 == 0), my_list)) # display the result print("Numbers divisible by 13 are",result) 

Output

 Numbers divisible by 13 are [65, 39, 221] 

Also Read:

Before we wrap up, let's put your understanding of this example to the test! Can you solve the following challenge?

Challenge:

Write a function to check if a number is divisible by five.

  • Return True if the number is divisible by 5. Otherwise, return False.
Did you find this article helpful?

Your builder path starts here. Builders don't just know how to code, they create solutions that matter.

Escape tutorial hell and ship real projects.

Try Programiz PRO
  • Real-World Projects
  • On-Demand Learning
  • AI Mentor
  • Builder Community