
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find Factors of Number using Python
In order to find factors of a number, we have to run a loop over all numbers from 1 to itself and see if it is divisible.
Example
num=int(input("enter a number")) factors=[] for i in range(1,num+1): if num%i==0: factors.append(i) print ("Factors of {} = {}".format(num,factors))
If i is able to divide num completely, it is added in the list. Finally the list is displayed as the factors of given number
Output
enter a number75 Factors of 75 = [3, 5, 15, 25, 75]
Advertisements