#!/usr/bin/env python3 # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. from sys import argv def get_int(msg): while True: try: i = int(input(msg)) return i except ValueError as err: print(err) continue def try_divide(value): try: first = int(value/2) except ValueError: first = value // 2 possible = [] while first != 0: try: second = int(value/first) possible.append(first) possible.append(second) except ValueError: continue first -= 1 return possible def print_true(possible, value): a = 0 b = 1 while a < len(possible) and b < len(possible): if possible[a] * possible[b] == value: print("({0}, {1})".format(possible[a], possible[b])) a += 1 b += 1 def main(): try: value = int(argv[-1]) except ValueError: print("Usage: {0} [number]".format(argv[0]), "\nQuickly find factors of a given number, unlike \"factor\".", "\nLimited to only positive counting numbers.", "\nFirst factor is omitted: number * 1 \n") value = get_int("Number? ") possible = try_divide(value) print_true(possible, value) if __name__ == "__main__": main()