Learn about Find Factors of a Number using While Loop in Python in the below code example. Also, refer to the comments in the code snippet to get a detailed view about what’s actually happening.
Contents
Find Factors of a Number using While Loop in Python
This is the clearest possible method for finding factors of a number program in Python. While declaring the variables, we will take a number. Python program that uses a while-loop to identify factors of a number and displays the results on the screen.
Source code:
# Python program to find factors of a number
# user input
num = int(input('Enter number: '))
# find factors of number
print('The factors of', num, 'are:')
i = 1
while (i <= num):
if(num % i == 0):
print(i, end=' ')
i = i+1
Output:
Enter number: 12
The factors of 12 are: 1 2 3 4 6 12
Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.
Similar Code : Program to Find Factors of a Number in Python