Algorithm
-
Input: Accept the number for which you want to find divisors (let's call it
dividend
) and the divisor. -
Initialize an empty list to store the results (divisible numbers).
Loop through a range of numbers starting from 1 to the
dividend
.a. For each number in the range:
i. Check if the current number is divisible by the divisor without any remainder.
ii. If divisible, add the number to the list of results.
-
Print or return the list of divisible numbers.
Code Examples
#1 Example- Find Numbers Divisible by Another Number in Python
Code -
Python Programming
def find_divisible_numbers(numbers, divisor):
divisible_numbers = []
for number in numbers:
if number % divisor == 0:
divisible_numbers.append(number)
return divisible_numbers
# Example usage
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
divisor = 5
divisible_numbers = find_divisible_numbers(numbers, divisor)
print(f"Numbers divisible by {divisor}: {divisible_numbers}")
Copy The Code &
Try With Live Editor
Output
#2 Example- Python Program to Check if a Number is Divisible by 3 and 5
Code -
Python Programming
# Find numbers divisible by 3 and 5 in Python
def check_divisibility(number):
if number % 3 == 0 and number % 5 == 0:
return True
else:
return False
# Example usage
num = int(input("Enter a number: "))
if check_divisibility(num):
print(f"The number {num} is divisible by both 3 and 5.")
else:
print(f"The number {num} is not divisible by both 3 and 5.")
Copy The Code &
Try With Live Editor
Output
The number 990 is divisible by both 3 and 5
#3 Example- Python Program to Check if a Number is Divisible by 2
Code -
Python Programming
# Check if number is divisible by 2 in Python
def check_divisibility(number):
if number % 2 == 0:
return True
else:
return False
# Example usage
num = int(input("Enter a number: "))
if check_divisibility(num):
print(f"The number {num} is divisible by 2.")
else:
print(f"The number {num} is not divisible by 2.")
Copy The Code &
Try With Live Editor
Output
The number 77 is not divisible by 2.
#4 Example- Python Program to Check Whether a Number is Divisible by 5 and 11 or not
Code -
Python Programming
# Check if a number is divisible by both 5 and 11
def check_divisibility(number):
if number % 5 == 0 and number % 11 == 0:
return True
else:
return False
# Example usage
num = int(input("Enter a number: "))
if check_divisibility(num):
print(f"The number {num} is divisible by both 5 and 11.")
else:
print(f"The number {num} is not divisible by both 5 and 11.")
Copy The Code &
Try With Live Editor
Output
The number 55 is divisible by both 5 and 11.
Demonstration
Python Programing Example to Find Numbers Divisible by Another Number-DevsEnv