Skip to content

Commit

Permalink
Added support for negative numbers and 0
Browse files Browse the repository at this point in the history
  • Loading branch information
ghemsley committed Oct 10, 2017
1 parent 4e4462c commit ea33467
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions factor.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ def factor(__n):

__factorList = []

for __i in range(1,__n+1):
if __n % __i == 0:
__factorList.append(__i)
if __n > 0 or __n < 0:
for __i in range(1,abs(int(__n)+1)):
if __n % __i == 0:
__factorList.append(__i)
elif __n == 0:
__factorList.append("Undefined")
return __factorList

def main():
Expand All @@ -18,7 +21,7 @@ def main():
__args = None

__parser = argparse.ArgumentParser()
__parser.add_argument("number", help="Number to factor", type=int)
__parser.add_argument("number", help="Number to factor", type=float)
__args = __parser.parse_args()
print(str(factor(__args.number)))
exit()
Expand Down

0 comments on commit ea33467

Please sign in to comment.