Skip to content

Commit

Permalink
Update prime_calc
Browse files Browse the repository at this point in the history
Updates on the function preserving only calculations. Functions variables are now global. Print logic changed to avoid errors.
  • Loading branch information
erickofs committed Dec 3, 2023
1 parent dba1856 commit 2efe62d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions desafio-02/erickofs/python/prime_calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@

# print(sieve_of_eratosthenes())

primelimit = int(input("Enter the calculation limit: "))
primerange = int(input("Enter the number of prime numbers to be displayed (0 = all): "))
primelist = set(range(2, primelimit))

def sieve_of_eratosthenes_set():
"""
Implements the Sieve of Eratosthenes algorithm to find all prime numbers up to the given limit.
Returns:
- primelist (set): Set of prime numbers up to the user's nth given range.
"""
primelimit = int(input("Enter the calculation limit: "))
primerange = int(input("Enter the number of prime numbers to be displayed (0 = all): "))
primelist = set(range(2, primelimit))

for i in range(2, int(primelimit**0.5) + 1):
for j in range(i*2, primelimit, i):
if j in primelist:
Expand All @@ -44,4 +44,4 @@ def sieve_of_eratosthenes_set():
return list(primelist)[:primerange] if primerange != 0 else list(primelist)

for prime in sieve_of_eratosthenes_set():
print(prime)
print(prime)

0 comments on commit 2efe62d

Please sign in to comment.