From da4a105bb772fae37d0f741be8e8ce329d3232f8 Mon Sep 17 00:00:00 2001 From: WORLDSAVER Date: Mon, 15 Aug 2022 21:36:27 +0530 Subject: [PATCH] Added Prime Number checker alorithm --- algorithms/Python/README.md | 4 ++++ algorithms/Python/number_theory/prime_number.py | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 algorithms/Python/number_theory/prime_number.py diff --git a/algorithms/Python/README.md b/algorithms/Python/README.md index b2be029d..7cfd6fa9 100644 --- a/algorithms/Python/README.md +++ b/algorithms/Python/README.md @@ -83,3 +83,7 @@ ## Queues - [First in First out Queue](queues/fifo-queue.py) + + +##Number Theory +- [Prime Number Checker][number_theory/prime_number.py] \ No newline at end of file diff --git a/algorithms/Python/number_theory/prime_number.py b/algorithms/Python/number_theory/prime_number.py new file mode 100644 index 00000000..54190ab1 --- /dev/null +++ b/algorithms/Python/number_theory/prime_number.py @@ -0,0 +1,16 @@ +#TO CHECK WHETHER A NUMBER IS PRIME OR NOT + + +N = int(input()) + +PRIME = True + +for i in range(2, int(N**0.5+1)): + if N%i==0: + PRIME = False + break + +if PRIME: + print(f"{N} is prime") +else: + print(f"{N} is not prime") \ No newline at end of file