Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create seriespattern10 #928

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Series Patterns/seriespattern10
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Function to check if a number is prime
def is_prime(num):
# Numbers less than 2 are not prime
if num < 2:
return False
# Check for divisibility from 2 to square root of num
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
return False
return True

# Function to print prime numbers up to n
def print_primes(n):
print("Prime numbers up to", n, "are:")
# Check each number from 2 to n
for num in range(2, n + 1):
# If the number is prime, print it
if is_prime(num):
print(num, end=" ")
print() # Print a newline at the end

# Set the upper limit
n = 20

# Call the function to print prime numbers
print_primes(n)

"""
OUTPUT:
Prime numbers up to 20 are:
2 3 5 7 11 13 17 19
"""