Skip to content

Instantly share code, notes, and snippets.

@patrickbeeson
Created September 7, 2014 17:42
Show Gist options
  • Save patrickbeeson/17724281447a10273a7a to your computer and use it in GitHub Desktop.
Save patrickbeeson/17724281447a10273a7a to your computer and use it in GitHub Desktop.
Find factors of a number
# factors.py
# Get integer input from user
userInteger = int(input('Enter a positive integer: '))
def findIntegers(userInteger):
"""
Find all factors of a number.
"""
# Ensure the number is positive
while userInteger <= 0:
userInteger = int(input('Your integer is not positive'
', please try again: '))
for n in range(1, (userInteger + 1)):
if userInteger % n == 0:
print('{} is a divisor of {}'.format(n, userInteger))
else:
pass
findIntegers(userInteger)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment