Find the divisor of the value entered in python

Introduction

This is a memo of the program code for finding the divisor.

Program code

div = []
num = int(input())
if num >= 2:
    for j in range(num):
        if num % (j + 1) == 0:
            div.append(j + 1)
    else:
        print(div)

easy explanation

The input value is divided by the loop processing of the for statement, and only when the remainder when divided is 0 is added to the array. Finally, the array is output.

Execution result

Input value
28

Output value
[1, 2, 4, 7, 14, 28]

Recommended Posts

Find the divisor of the value entered in python
Find the solution of the nth-order equation in python
Find the difference in Python
Find the definition of the value of errno
[Python] Find the second smallest value.
Find out the apparent width of a string in python
Python --Find out number of groups in the regex expression
Find the eigenvalues of a real symmetric matrix in Python
Find the maximum value python (fixed ver)
Check the behavior of destructor in Python
The result of installing python in Anaconda
The basics of running NoxPlayer in Python
In search of the fastest FizzBuzz in Python
Find the maximum Python
Output the number of CPU cores in Python
[Python] Sort the list of pathlib.Path in natural sort
Find the mood value with python (Rike Koi)
Get the caller of a function in Python
Match the distribution of each group in Python
View the result of geometry processing in Python
Make a copy of the list in Python
Find the number of days in a month
Prime factorization of integers entered in Python ver.1
List find in Python
The story of reading HSPICE data in Python
[Note] About the role of underscore "_" in Python
About the behavior of Model.get_or_create () of peewee in Python
Solving the equation of motion in Python (odeint)
Output in the form of a python array
Search by the value of the instance in the list
Find the geometric mean of n! Using Python
[Python] Find the transposed matrix in a comprehension
python xlwings: Find the cell in the last row
[Scientific / technical calculation by Python] Numerical calculation to find the value of derivative (differential)
Compare the sum of each element in two lists with the specified value in Python
How to find the coefficient of the trendline that passes through the vertices in Python
How to retrieve the nth largest value in Python
Experience the good calculation efficiency of vectorization in Python
Find out the location of Python class definition files.
[Python] Calculate the average value of the pixel value RGB of the object
[python] Get the list of classes defined in the module
The story of FileNotFound in Python open () mode ='w'
Learn the design pattern "Chain of Responsibility" in Python
Implement the solution of Riccati algebraic equations in Python
Find the part that is 575 from Wikipedia in Python
[Golang] Specify an array in the value of map
Get the size (number of elements) of UnionFind in Python
Get the value selected in Selenium Python VBA pull-down
Not being aware of the contents of the data in python
Find the Hermitian matrix and its eigenvalues in Python
Reproduce the execution example of Chapter 4 of Hajipata in Python
Let's use the open data of "Mamebus" in Python
Implemented the algorithm of "Algorithm Picture Book" in Python3 (Heapsort)
[Python] Outputs all combinations of elements in the list
Get the URL of the HTTP redirect destination in Python
A reminder about the implementation of recommendations in Python
Reproduce the execution example of Chapter 5 of Hajipata in Python
To do the equivalent of Ruby's ObjectSpace._id2ref in Python
Check the asymptotic nature of the probability distribution in Python
Towards the retirement of Python2
Download the file in Python