Skip to content

Instantly share code, notes, and snippets.

@AliSajid
Created February 2, 2017 19:43
Show Gist options
  • Save AliSajid/1116952ca0206350e24d13ed221dce37 to your computer and use it in GitHub Desktop.
Save AliSajid/1116952ca0206350e24d13ed221dce37 to your computer and use it in GitHub Desktop.
# Define the factorize function
def factorize(number):
factors = [i, int(n/i) for i in range(1, 1+number/2) if number % i == 0]
return set(sorted(factors))
# Define the printing function
def print_factors(factor_array):
for n in factor_array:
print("{} is a factor".format(n))
# Ask for the number
n = int(input("Please enter the number you need the factors of: "))
print("Factorizing the integer...")
print_factors(factorize(n))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment