From c6c4f9c37cf7d0aa7910924aafaa43dd36febbbb Mon Sep 17 00:00:00 2001 From: esouidi <75025946+esouidi@users.noreply.github.com> Date: Sat, 4 Dec 2021 03:46:29 +0100 Subject: [PATCH] Issue #74 print primes with for loop Added print_primes_with_for function, answering the issue. --- Language/python/Program1/main.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Language/python/Program1/main.py b/Language/python/Program1/main.py index ce4b867..fa965d5 100644 --- a/Language/python/Program1/main.py +++ b/Language/python/Program1/main.py @@ -14,10 +14,20 @@ def print_primes(lower_limit: int, upper_limit: int) -> None: lower_limit += 1 + +def print_primes_with_for(lower_limit: int, upper_limit: int) -> None: + for i in range(lower_limit, upper_limit + 1): + if i > 1: + interval = 2 + for k in range(interval, i): + if i % k == 0: + break + else: + print(i) # Taking inputs lower = int(input("Lower Limit: ")) upper = int(input("Upper Limit: ")) -print_primes(lower, upper) +print_primes_with_for(lower, upper)