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