-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestTar4.py
50 lines (40 loc) · 1.36 KB
/
testTar4.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# -*- coding: utf-8 -*-
"""
Created on Tue Jun 16 19:10:21 2020
"""
# Count primes function
def count_Primes(num):
ctr = 0
for num in range(num):
if num <= 1:
continue
for i in range(2, num):
if (num % i) == 0:
break
else:
ctr += 1
return ctr
# Is it a prime number function
def isprime(num):
if num > 1:
# check for factors
for i in range(2,num):
if (num % i) == 0:
return(str(num) + " is not a prime number" +
"\n" + " There are " + str(count_Primes(num)) +
"\n" + "Prime numbers between 1 and " + str(num))
break
else:
return(str(num) + " is a prime number"+
"\n" + " There are " + str(count_Primes(num)) +
"\n" + "Prime numbers between 1 and " + str(num))
else:
return(str(num) + " is not a prime number"+
"\n" + " There are " + str(count_Primes(num)) +
"\n" + "Prime numbers between 1 and " + str(num))
# Gets number and check if it's a prime number and how many primes came before
num =int(input('Please enter a positive number: '))
if num>0:
print(isprime(num))
else:
print("You have entered a negative number - Finished")