Created
February 5, 2019 23:50
-
-
Save pdbartsch/dd00635c32a2791c64693b2c76945164 to your computer and use it in GitHub Desktop.
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
# https://www.practicepython.org/exercise/2014/02/26/04-divisors.html | |
import math | |
invar = input("Please enter an integer. Then I'll return a list of all divisors of that number: ") | |
def divisors(n): | |
divisors = [ x for x in range(1,n+1) if n % x == 0] | |
print(*divisors, sep=', ') | |
try: | |
# deal with float inputs | |
n = math.floor(float(invar)) | |
ceil = math.ceil(float(invar)) | |
if ceil - n > 0: | |
print('Your number was rounded to ' + str(n) + '. The divisors of ' + str(n) + ' are:') | |
else: | |
print('The divisors of ' + str(n) + ' are:') | |
divisors(n) | |
# deal with non-numeric input | |
except: | |
print("I don't think that was a number. Try again.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment