Python program to print prime numbers from 1 to n; In this tutorial, you will learn how to print prime numbers from 1 to n (10, 100, 500, 1000) using for loop and while loop in python.

## Python Program to Print Prime Number From 1 to N(10, 100, 500, 1000)

- Python Program to find Prime Number using For Loop
- Python Program To Print Numbers From 1 to N Using For Loop
- Python Program To Print Numbers From 1 to N Using While Loop
- Python program to find sum of all prime numbers between 1 to n

### Python Program to find Prime Number using For Loop

```
Python Program to Check A given Number is Prime Or Not
Num = int(input(" Please Enter any Number: "))
count = 0
for i in range(2, (Num//2 + 1)):
if(Num % i == 0):
count = count + 1
break
if (count == 0 and Num != 1):
print(" %d is a Prime Number" %Num)
else:
print(" %d is not a Prime Number" %Num)
```

**Output**

Please Enter any Number: 50 50 is not a Prime Number

### Python Program To Print Numbers From 1 to N Using For Loop

```
# Python Program to print n prime number using for loop
Number = int(input(" Please Enter any Number: "))
print("Prime numbers between", 1, "and", Number, "are:")
for num in range(1, Number + 1):
# all prime numbers are greater than 1
if num > 1:
for i in range(2, num):
if (num % i) == 0:
break
else:
print(num)
```

**Output**

Please Enter any Number: 25 Prime numbers between 1 and 25 are: 2 3 5 7 11 13 17 19 23

### Python Program To Print Numbers From 1 to N Using While Loop

```
# Python Program to print Prime Numbers from 1 to N
max = int(input(" Please Enter Any Number: "))
Number = 1
print("Prime numbers between", 1, "and", max, "are:")
while(Number <= max):
count = 0
i = 2
while(i <= Number//2):
if(Number % i == 0):
count = count + 1
break
i = i + 1
if (count == 0 and Number != 1):
print(" %d" %Number, end = ' ')
Number = Number + 1
```

**Output**

Please Enter Any Number: 15 Prime numbers between 1 and 15 are: 2 3 5 7 11 13

### Python program to find sum of all prime numbers between 1 to n

```
# Python Program to print n prime number using for loop
max = int(input("Find sum of prime numbers upto : "))
sum = 0
for num in range(2, max + 1):
i = 2
for i in range(2, num):
if (int(num % i) == 0):
i = num
break;
#If the number is prime then add it.
if i is not num:
sum += num
print("\nSum of all prime numbers upto", max, ":", sum)
```

**Output**

Find sum of prime numbers upto : 25 Sum of all prime numbers upto 25 : 98

### Simple Python Programs

- Python Program to Add Two Numbers
- Python Program to Find/Calculate Sum of n Numbers
- Python Program to Find/Calculate Average of 3, 4, 5…n numbers
- Python Program to Print ASCII Value of Character
- Write a Program to Calculate Simple Interest in Python
- Python Program to Compute Compound Interest
- Leap Year Program in Python
- Python Program to Print Star Pattern
- Number Pattern Programs in Python
- Python Program to Print Even and Odd numbers From 1 to N
- Python Abs() Function: For Absolute Value
- How to Check Whether a Number is Fibonacci or Not in Python
- Python: Program to Find Power of Number
- Python Program to Reverse a Numbers
- Python Program to Find Smallest/Minimum of n Numbers
- Python Program to Find Largest/Maximum of n Numbers
- Python Program to Find The Net Bill Amount After Discount
- Python Program to Print Numbers From N to 1 and 1 to N
- Python Program to Print Numbers Divisible by 3, 5, 7
- How to Find Square of Number in Python
- Python Program to Calculate Cube of Number
- Python Program to Find LCM of Two Numbers
- BMI (Body Mass Index) Calculator in Python
- Palindrome Program in Python using while loop, Function, etc
- Python: Program to Count Total Number of Bits in Number
- Python Random Number Generator Code
- Python Program to Calculate n-th term of a Fibonacci Series
- Zip Zap Zoom Python Program
- Python: program to convert Celsius to Fahrenheit
- Python Program to Swap Two Numbers
- Python Program to Get Standard Deviation
- Python Program to Find the Variance
- Python Program to Convert Height in cm to Feet and Inches
- Python Program to Convert Meters into Yards, Yards into Meters
- Python Program to Convert Kilometers to Meters, Miles
- Python Program to Find Perfect Number
- Python: Program to Find Strong Number
- Python Program Create Basic Calculator
- Python Program For math.floor() Method
- Python Program to Find Sum of Series 1/1! 2/2! 3/3! …1/n!