-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11_check_primality_func.py
30 lines (25 loc) · 1.05 KB
/
11_check_primality_func.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
###############################################################################
# Exercise 11: Check Primality Functions (PracticePython)
# Author: Jenny Hamer
#
# Description: Prompt the user for a number and determine whether or not it
# is prime. Return the result.
###############################################################################
# Given num, an integer, try dividing it by all numbers between [2, num)
def get_divisor(num):
possible_divisors = [x for x in range(2, num)]
# print(possible_divisors)
prime = True
for x in possible_divisors:
if num % x == 0:
prime = False
print("Looks like", num, "is composite!", x, "divides it.")
break
print("We found no divisors of", num, "besides 1 and itself. It's a prime!")
while True:
try:
user_val = int(input("Please enter a number to check whether it is prime: "))
break
except ValueError:
print("Looks like you didn't enter a valid number. Please try again...")
get_divisor(user_val)