From c2587c76f1b416cdbecb979e54941933246bf856 Mon Sep 17 00:00:00 2001 From: Skip Montanaro Date: Tue, 16 Feb 2021 20:14:16 -0600 Subject: starting over --- lib/fact.py | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'lib/fact.py') diff --git a/lib/fact.py b/lib/fact.py index ba961c4..2beb0cb 100644 --- a/lib/fact.py +++ b/lib/fact.py @@ -3,35 +3,35 @@ import sys import math -error = 'fact.error' # exception +error = 'fact.error' # exception def fact(n): - if n < 1: raise error # fact() argument should be >= 1 - if n = 1: return [] # special case - res = [] - _fact(n, 2, res) - return res + if n < 1: raise error # fact() argument should be >= 1 + if n = 1: return [] # special case + res = [] + _fact(n, 2, res) + return res def _fact(n, lowest, res): - highest = int(math.sqrt(float(n+1))) - for i in range(lowest, highest+1): - if n%i = 0: - res.append(i) - _fact(n/i, i, res) - break - else: - res.append(n) + highest = int(math.sqrt(float(n+1))) + for i in range(lowest, highest+1): + if n%i = 0: + res.append(i) + _fact(n/i, i, res) + break + else: + res.append(n) def main(): - if len(sys.argv) > 1: - for arg in sys.argv[1:]: - n = eval(arg) - print n, fact(n) - else: - try: - while 1: - print fact(input()) - except EOFError: - pass + if len(sys.argv) > 1: + for arg in sys.argv[1:]: + n = eval(arg) + print n, fact(n) + else: + try: + while 1: + print fact(input()) + except EOFError: + pass main() -- cgit v1.2.3