From 150387807267107741610ab990b45e36f58712aa Mon Sep 17 00:00:00 2001 From: Stefano Agnelli Date: Sat, 7 Dec 2024 20:10:38 +0100 Subject: [PATCH] solution m3-015 --- .../python/main.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/projects/015-the-sieve-of-eratosthenes/python/main.py b/projects/015-the-sieve-of-eratosthenes/python/main.py index e69de29b..4f46776f 100644 --- a/projects/015-the-sieve-of-eratosthenes/python/main.py +++ b/projects/015-the-sieve-of-eratosthenes/python/main.py @@ -0,0 +1,22 @@ +user_limit = int(input('Insert a limit: ')) + +list_num = list(range(2, user_limit - 1)) +limit = list_num[-1] +p = 2 + +while p <= limit: + if list_num[p-2] == 0: + p += 1 + + else: + for n in range(limit): + multi = p * n + + if list_num.count(multi) != 0 and multi != p: + position = list_num.index(multi) + remove = list_num.pop(position) + list_num.insert(position, 0) + + p += 1 + +print(list_num)