Here, we will figure out how to print all numbers from the string which are distinguishable by M an N in Python?
Given a list of the integers and M, N and we need to print the numbers which are distinguishable by M, N in Python.
Example:
Input:
List = [10, 15, 20, 25, 30]
M = 3, N=5
Output:
15
30
To discover and print the list of the numbers which are distinguishable by M and N, we need to navigate all components utilizing a circle and check whether the number is separable by M and N if the number is distinct 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