Python Program - Find Numbers Divisible by Another Number

‮gi.www‬iftidea.com

Here's a Python program that finds numbers divisible by another number:

def find_divisible_numbers(numbers, divisor):
    divisible_numbers = []
    for num in numbers:
        if num % divisor == 0:
            divisible_numbers.append(num)
    return divisible_numbers

numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
divisor = 3
divisible_numbers = find_divisible_numbers(numbers, divisor)
print(f"Numbers divisible by {divisor}: {divisible_numbers}")

Output:

Numbers divisible by 3: [3, 6, 9]

In this program, we define a function find_divisible_numbers that takes two arguments, numbers and divisor. The numbers argument is a list of numbers, and the divisor argument is the number by which we want to find the divisible numbers.

We create an empty list divisible_numbers to store the numbers that are divisible by the divisor. We iterate over each number in the numbers list using a for loop, and check if it is divisible by the divisor using the modulo operator %. If the number is divisible by the divisor, we append it to the divisible_numbers list. Finally, we return the divisible_numbers list.

In the main program, we create a list of numbers numbers and a divisor divisor. We call the find_divisible_numbers function with these arguments to get the list of numbers that are divisible by divisor. Finally, we print the result.