In [1]:
import math
number = int (input ('Enter a number: '))
sqrt_value = int (math.sqrt(number))
#print (sqrt_value)
for i in range(1, sqrt_value + 1):
if number % i == 0:
if i * i == number:
print (i, end = ' ')
else:
print (i, int(number/i), end = ' ')
Enter a number: 16 1 16 2 8 4
In [2]:
number = int (input ('Enter a number: '))
print ('Factors of ', number, ' are: ')
for i in range(1, number + 1):
if number % i == 0:
print (i, end = ', ')
Enter a number: 12 Factors of 12 are: 1, 2, 3, 4, 6, 12,
No comments:
Post a Comment