
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python Program to Find the Smallest Divisor of an Integer
When it is required to find the smallest divisor of a an integer, a simple ‘for’ loop is used.
Below is a demonstration of the same −
Example
first_num = int(input("Enter a number...")) my_list = [] print("The number is ") print(first_num) for i in range(2,first_num+1): if(first_num%i==0): my_list.append(i) my_list.sort() print("The smallest divisor is : ") print(my_list[0])
Output
Enter a number...56 The number is 56 The smallest divisor is : 2
Explanation
The number is taken as an input from the user.
An empty list is defined.
The number taken from user is displayed on the console.
The number range is iterated over.
It is checked to see if the number divided by the iterator is 0.
If yes, it is appended to the empty list.
In the end, this list is sorted.
The first element of the sorted list is displayed on the console, since this is the smallest divisor.
- Related Articles
- Golang Program to Find the Smallest Divisor of an Integer
- Python program to find better divisor of a number
- Find an integer X which is divisor of all except exactly one element in an array in Python
- Find the Smallest Divisor Given a Threshold in C++
- Program to find out the sum of the number of divisor of the divisors in Python
- Find the k-th smallest divisor of a natural number N in C++
- Find an integer X which is divisor of all except exactly one element in an array in C++
- Program to find probability that any proper divisor of n would be an even perfect square number in Python
- Python program to find the sum of all even and odd digits of an integer list
- Java program to find the smallest number in an array
- C# Program to find the smallest element from an array
- Python program to find the smallest number in a list
- Program to find kth smallest n length lexicographically smallest string in python
- Smallest Integer Divisible by K in Python
- Java program to find Largest, Smallest, Second Largest, Second Smallest in an array

Advertisements