Created
September 7, 2014 17:42
-
-
Save patrickbeeson/17724281447a10273a7a to your computer and use it in GitHub Desktop.
Find factors of a number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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