Created
February 8, 2023 08:00
-
-
Save Denenberg/94389c3d59c83092a4b66df6d9a2f6a8 to your computer and use it in GitHub Desktop.
Here's a simple Python program that prints the first n numbers each of them is a product of 1 distinct primes:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Here's a simple Python program that prints the first n numbers | |
# each of them is a product of 1 distinct primes: | |
# This program uses a simple algorithm to generate | |
# prime numbers up to a certain limit (n), and then prints the | |
# first n prime numbers. | |
def get_primes(n): | |
primes = [] | |
candidate = 2 | |
while len(primes) < n: | |
is_prime = True | |
for prime in primes: | |
if candidate % prime == 0: | |
is_prime = False | |
break | |
if is_prime: | |
primes.append(candidate) | |
candidate += 1 | |
return primes | |
def main(): | |
n = int(input("Enter the number of prime products to print: ")) | |
primes = get_primes(n) | |
for i in range(n): | |
print(primes[i]) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment