Python Program to print all prime numbers between 1 to n


In this program, You will learn how to print all prime numbers between 1 to n in Python.


Some list are: 2 3 5 7 9 11 13

Example: How to print all prime numbers between 1 to n in Python.

n = int(input("Enter number :"))

i = 2

for i in range(i, n + 1):
    k = 2
    p = 1
    while k < i:
        if i % k == 0:
            p = 0
            break
        k = k + 1
    if p == 1:
        print("Number is prime:", i)
    i = i + 1

Output:

Enter number :10
Number is prime: 2
Number is prime: 3
Number is prime: 5
Number is prime: 7