def num_factors(number): possible_factor = 2 number_factors = 2 st = math.sqrt(number) while possible_factor < st: if my_module.is_factor(possible_factor, number): number_factors += 2 possible_factor += 1 if possible_factor == st: number_factors += 1 if number == 1: return 1 else: return number_factors
def test_is_factor(self): self.assertTrue(my_module.is_factor(2, 4)) self.assertFalse(my_module.is_factor(5, 7)) self.assertTrue(my_module.is_factor(193, 193))
def get_proper_divisors(n): divisors = [1] for i in xrange(2, n/2 + 1): if my_module.is_factor(i, n): divisors.append(i) return divisors