-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathdefnum.py
More file actions
68 lines (49 loc) · 2.07 KB
/
defnum.py
File metadata and controls
68 lines (49 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python3
"""Python script to save, as a list, a series of numbers that
are deficient. Numbers are deficient if sum(m) < 2 * m, whith sum(m) being
the summation of m's divisors. Scripts gives the option to print the list of
deficient nubmers.
"""
def print_deficients(begin: int, end: int) -> int:
"""print_deficients(begin, end) -> int:
Calculates if a series of number between begin, and end, [inclusive] are
deficient and appends the deficient number to a list
parameters:
begin: [int]: First number to calculate
end: [int]: Last number to calculate
returns:
deficient_nums: list[int]: List of deficient numbers calculated
"""
deficient_nums: list[int] = []
while begin <= end:
# We stop iterating half-way to begin and since begin is a divisor of
# begin we set divisors variable to begin
divisors: int = begin
index: int = 1
# Iterate to half of begin since numbers greater than (begin / 2) will
# not be divisors
while index <= begin // 2:
if begin % index == 0: # Checks if divisor
divisors += index # sums divisor if i is a divisor
index += 1
if divisors < 2 * begin: # Checks for deficiency
deficient_nums.append(begin) # Appends to list if deficient
begin += 1 # Increment one number closer to end variable
return deficient_nums
def check_if_deficient():
"""check_fi_dificient():
TODO: Future implimentation.
"""
pass
def main() -> None:
# Gets users start and stop value. Raises ValueError if number is not an int
start = int(input("Enter start number: "))
stop = int(input("Enter stop number: "))
# start, stop = 940, 950
deficients = print_deficients(start, stop)
# Query's user if they wish to print the returned list of dificient nubers
if str(input("Enter 'y' to print the dificient numbers: ").lower()) == "y":
print()
[print(f"{number} is deficient") for number in deficients]
if __name__ == "__main__":
main()