Factors of a Number - Learn Engineering

All the news and updates relevant to Engineering. You can also Write a post here

Breaking

Friday, June 19, 2020

Factors of a Number

python-mini

Question

To Print the Factors of given number.

Sample TestCaseExpected Output

Enter a number : 5                                                                            The Factors of 5 are :

                                                                                                                           1
                                                                                                                           5          





Answer


def print_factors(x):
    print("The factors of",x,"are :")
    for i in range(1,x+1):
        if x%i==0:
            print(i)
num = int(input("Enter a number : "))
print_factors(num)


No comments:

Post a Comment