-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfactors
More file actions
executable file
·35 lines (23 loc) · 753 Bytes
/
factors
File metadata and controls
executable file
·35 lines (23 loc) · 753 Bytes
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
#!/usr/bin/env python3
from sys import argv
from math import sqrt
def read_test_file(file_name):
"""Function to read numbers from file: one on each line"""
with open(file_name, "r", encoding="utf-8") as file:
lines = file.readlines()
number_to_factor = []
for line in lines:
number_to_factor.append(int(line))
return number_to_factor
def find_numbers(n):
"""Function to find factors of current number"""
for i in range(1, n):
if n == ((n // i) * i):
print("{}={}*{}".format(n, (n // i), i))
break
def factors(ls):
"""Function to iterate between numbers in file"""
for i in ls:
find_numbers(i)
if len(argv) == 2:
factors(read_test_file(argv[1]))