Program 19
Write a function called number_of_factors that takes an integer and returns how many factors the number has.
def number_of_factors(num):
count=0
for i in range(1,num+1):
if(num%i==0):
print(i,end=" ")
count=count+1
return(count)
num=int(input("Enter the integer:"))
c=number_of_factors(num)
print("\n factors the %d number has =%d"%(num,c))
output:
>>>
======= RESTART: D:\old\r19 lab-python\19.py ===============
Enter the integer:25
1 5 25
factors the 25 number has =3
>>>
=========== RESTART: D:\old\r19 lab-python\19.py ============
Enter the integer:16
1 2 4 8 16
factors the 16 number has =5
>>>
No comments:
Post a Comment