Skip to content

Instantly share code, notes, and snippets.

@Hwatwasthat
Created February 21, 2018 10:55
Show Gist options
  • Select an option

  • Save Hwatwasthat/07132a2db84d1aa377b8f4434a9c2d74 to your computer and use it in GitHub Desktop.

Select an option

Save Hwatwasthat/07132a2db84d1aa377b8f4434a9c2d74 to your computer and use it in GitHub Desktop.
Divisors created by Hwatwasthat - https://repl.it/@Hwatwasthat/Divisors
#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