arten_1337

Factors of a Number

Mar 10th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.33 KB | None | 0 0
  1. from math import sqrt
  2.  
  3.  
  4. def factors(num):
  5.     count = 0
  6.     ite = int(sqrt(num))
  7.     i = 1
  8.     while(i <= ite):
  9.         if num % i == 0:
  10.             count += 1
  11.         i += 1
  12.     count = 2 * count
  13.     if ite * ite == num:
  14.         count -= 1
  15.     return count
  16.  
  17. test_case = int(input("Enter a number to find no of factors: "))
  18. print('Factors count: ', factors(test_case))
Advertisement
Add Comment
Please, Sign In to add comment