MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / factors

Function factors

maths/special_numbers/weird_number.py:10–29  ·  view source on GitHub ↗

>>> factors(12) [1, 2, 3, 4, 6] >>> factors(1) [1] >>> factors(100) [1, 2, 4, 5, 10, 20, 25, 50] # >>> factors(-12) # [1, 2, 3, 4, 6]

(number: int)

Source from the content-addressed store, hash-verified

8
9
10def factors(number: int) -> list[int]:
11 """
12 >>> factors(12)
13 [1, 2, 3, 4, 6]
14 >>> factors(1)
15 [1]
16 >>> factors(100)
17 [1, 2, 4, 5, 10, 20, 25, 50]
18
19 # >>> factors(-12)
20 # [1, 2, 3, 4, 6]
21 """
22
23 values = [1]
24 for i in range(2, int(sqrt(number)) + 1, 1):
25 if number % i == 0:
26 values.append(i)
27 if int(number // i) != i:
28 values.append(int(number // i))
29 return sorted(values)
30
31
32def abundant(n: int) -> bool:

Callers 2

abundantFunction · 0.85
semi_perfectFunction · 0.85

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected