-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathexercise_6*.py
36 lines (29 loc) · 923 Bytes
/
exercise_6*.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
31
32
33
34
35
36
#This program finds every prime number less than or equal to input n
import math as m
def primeNum(n):
#check if n is evenly divisible by values between 2 and int(m.sqrt(n))
x = m.sqrt(n)
i = 2
while i <= x:
value = n % i
#if any value is divisble, break and close program
if value == 0:
return
#if no value is divisible evenly, print("The number is prime.")
else:
i = i + 1
print(n)
def main():
x = 0
#Validate x as a positive whole number
while True:
x = eval(input("Input a positive whole number: "))
if (x % 1 != 0):
x = print("The number you entered was not whole!")
elif (x < 1):
x = print("The number you entered was not positive!")
else:
break
for n in range(x):
primeNum(n+1)
main()