From 34f70ff7c8a8dfef1eeccf5065b8e51ae9bfc951 Mon Sep 17 00:00:00 2001 From: Aishanii <59767187+Aishanipach@users.noreply.github.com> Date: Wed, 7 Oct 2020 23:24:20 +0530 Subject: [PATCH] Create countprimes.py --- .../countprimes.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 python/Longest Increasing Subsequence/countprimes.py diff --git a/python/Longest Increasing Subsequence/countprimes.py b/python/Longest Increasing Subsequence/countprimes.py new file mode 100644 index 0000000..efa08cb --- /dev/null +++ b/python/Longest Increasing Subsequence/countprimes.py @@ -0,0 +1,20 @@ +#Count primes in a range + +def count_primes2(num): + primes = [2] + x = 3 + if num < 2: + return 0 + while x <= num: + for y in primes: # use the primes list! + if x%y == 0: + x += 2 + break + else: + primes.append(x) + x += 2 + print(primes) + return len(primes) + +num= int(input("Enter limit: ")) +count_primes2(num)