Created
February 21, 2018 10:55
-
-
Save Hwatwasthat/07132a2db84d1aa377b8f4434a9c2d74 to your computer and use it in GitHub Desktop.
Divisors created by Hwatwasthat - https://repl.it/@Hwatwasthat/Divisors
This file contains hidden or 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
| #Enter number for divisors here | |
| Num = int(input("What number do you want Divisors for?")) | |
| #Ensure number is positive | |
| if Num <= 0: | |
| print("Number must be positive") | |
| quit() | |
| #create range to work in | |
| range_nums = range(1, Num) | |
| #create list for all divisors | |
| list_divisors = [] | |
| #iterate over numbers in range | |
| for i in range_nums: | |
| #check if number is divisor by checking if number modulo it is 0 | |
| if Num % i == 0: | |
| #add number to list if divisor | |
| list_divisors.append(i) | |
| #print results, turning list elements into strings for printing | |
| print(", ".join(str(e) for e in list_divisors)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment