input: positive integer 'n' >= 1 returns all divisors of n (inclusive 1 and 'n')
(n)
| 513 | |
| 514 | |
| 515 | def 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 | # ---------------------------------------------------- |
no test coverage detected