scientific-programming-exer.../ex_11.py

29 lines
465 B
Python
Raw Normal View History

2018-11-07 14:22:04 +00:00
#!/usr/bin/python3
import pprint
from util.io import readvalue
def divisors(n):
return [i for i in range(2, n) if not n % i]
def is_prime(n):
return not divisors(n)
if( __name__ == "__main__"):
def positive_int(s):
v = int(s)
if(v > 0):
return v
number = readvalue("n > ", positive_int)
print("Divisors:")
pprint.pprint(divisors(number))
if(is_prime(number)):
print("Also", number, "is a prime.")
else:
print(number, "is not a prime.")