MCPcopy Create free account
hub / github.com/subbarayudu-j/TheAlgorithms-Python / getDivisors

Function getDivisors

other/primelib.py:491–515  ·  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

489# ----------------------------------------------------
490
491def getDivisors(n):
492 """
493 input: positive integer 'n' >= 1
494 returns all divisors of n (inclusive 1 and 'n')
495 """
496
497 # precondition
498 assert isinstance(n,int) and (n >= 1), "'n' must been int and >= 1"
499
500 from math import sqrt
501
502 ans = [] # will be returned.
503
504 for divisor in range(1,n+1):
505
506 if n % divisor == 0:
507 ans.append(divisor)
508
509
510 #precondition
511 assert ans[0] == 1 and ans[len(ans)-1] == n, \
512 "Error in function getDivisiors(...)"
513
514
515 return ans
516
517
518# ----------------------------------------------------

Callers 1

isPerfectNumberFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected