MCPcopy Create free account
hub / github.com/geekcomputers/Python / getDivisors

Function getDivisors

primelib/primelib.py:515–533  ·  view source on GitHub ↗

input: positive integer 'n' >= 1 returns all divisors of n (inclusive 1 and 'n')

(n)

Source from the content-addressed store, hash-verified

513
514
515def getDivisors(n):
516 """
517 input: positive integer 'n' >= 1
518 returns all divisors of n (inclusive 1 and 'n')
519 """
520
521 # precondition
522 assert isinstance(n, int) and (n >= 1), "'n' must been int and >= 1"
523
524 ans = [] # will be returned.
525
526 for divisor in range(1, n + 1):
527 if n % divisor == 0:
528 ans.append(divisor)
529
530 # precondition
531 assert ans[0] == 1 and ans[len(ans) - 1] == n, "Error in function getDivisiors(...)"
532
533 return ans
534
535
536# ----------------------------------------------------

Callers 1

isPerfectNumberFunction · 0.85

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected