# Python | Program to print all numbers which are divisible by M and N in the List

Here, we will learn how to **print all numbers from the string which are divisible by M an N in Python**?

Submitted by **IncludeHelp**, on July 27, 2018

**Given a list of the integers and M, N and we have to print the numbers which are divisible by M, N in Python.**

**Example:**

Input: List = [10, 15, 20, 25, 30] M = 3, N=5 Output: 15 30

To find and print the list of the numbers which are divisible by M and N, we have to traverse all elements using a loop, and check whether the number is divisible by M and N, if number is divisible by M and N both print the number.

**Program:**

# declare a list of integers list = [10, 15, 20, 25, 30] # declare and assign M and N M = 3 N = 5 # print the list print "List is: ", list # Traverse each element and check # whether it is divisible by M, N # or not, if condition is true print # the element print "Numbers divisible by {0} and {1}".format (M, N) for num in list: if( num%M==0 and num%N==0 ) : print num

**Output**

List is: [10, 15, 20, 25, 30] Numbers divisible by 3 and 5 15 30

TOP Interview Coding Problems/Challenges

- Run-length encoding (find/print frequency of letters in a string)
- Sort an array of 0's, 1's and 2's in linear time complexity
- Checking Anagrams (check whether two string is anagrams or not)
- Relative sorting algorithm
- Finding subarray with given sum
- Find the level in a binary tree with given sum K
- Check whether a Binary Tree is BST (Binary Search Tree) or not
- 1[0]1 Pattern Count
- Capitalize first and last letter of each word in a line
- Print vertical sum of a binary tree
- Print Boundary Sum of a Binary Tree
- Reverse a single linked list
- Greedy Strategy to solve major algorithm problems
- Job sequencing problem
- Root to leaf Path Sum
- Exit Point in a Matrix
- Find length of loop in a linked list
- Toppers of Class
- Print All Nodes that don't have Sibling
- Transform to Sum Tree
- Shortest Source to Destination Path

Comments and Discussions