Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Akash-Ansari/2c83d93b1a451a78c70ab437635551df to your computer and use it in GitHub Desktop.
Save Akash-Ansari/2c83d93b1a451a78c70ab437635551df to your computer and use it in GitHub Desktop.
# Printing prime numbers upto a certain number
def is_prime(num):
for i in range(2, num):
if (num % i) == 0:
return False
return True
def getPrimes(max_num):
list_of_primes = []
for num in range(2, max_num):
if is_prime(num):
list_of_primes.append(num)
return list_of_primes
max_num_to_check = int(input("Search for primes upto: "))
list_of_primes = getPrimes(max_num_to_check)
for prime in list_of_primes:
print(prime)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment