Write a Python Program to print Prime numbers from 1 to 100, or 1 to n, or minimum to maximum with example. Here, we will calculate the sum of prime numbers from 1 to n

**TIP:** I suggest you to refer Prime Number article to understand the logic.

## Python Program to print Prime Numbers from 1 to 100 using For Loop

This python program will print prime numbers form 1 to 100.

First, we used For Loop to iterate loop between 1 and 100 value. Within the for loop,

- We used another For loop to check whether the number is divisible or not. If true, count will be incremented, and break statement will skip that number
- Next, If statement is to check whether the count is zero, and given number is not equal to 1. If it is true, it will print the number because it is a prime Number

# Python Program to print Prime Numbers from 1 to 100 for Number in range (1, 101): count = 0 for i in range(2, (Number//2 + 1)): if(Number % i == 0): count = count + 1 break if (count == 0 and Number != 1): print(" %d" %Number, end = ' ')

**OUTPUT**

## Python Program to print Prime Numbers from 1 to 100 using While Loop

We just replaced the For loop in the above example with While loop.

# Python Program to print Prime Numbers from 1 to 100 Number = 1 while(Number <= 100): 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**

## Python Program to print Prime Numbers from 1 to N using For Loop

Instead of blindly printing prime numbers from 1 to 100, this program allow user to enter the minimum and maximum values. Next, it will print prime numbers between Minimum and Maximum values.

# Python Program to print Prime Numbers from 1 to N minimum = int(input(" Please Enter the Minimum Value: ")) maximum = int(input(" Please Enter the Maximum Value: ")) for Number in range (minimum, maximum + 1): count = 0 for i in range(2, (Number//2 + 1)): if(Number % i == 0): count = count + 1 break if (count == 0 and Number != 1): print(" %d" %Number, end = ' ')

**OUTPUT**

## Python Program to print Prime Numbers from 1 to N using While Loop

This program is same as above. We replaced the For loop with While Loop.

# Python Program to print Prime Numbers from 1 to N minimum = int(input(" Please Enter the Minimum Value: ")) maximum = int(input(" Please Enter the Maximum Value: ")) Number = minimum while(Number <= maximum): 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**

## Python Program to find Sum of Prime Numbers from 1 to 100

This program finds the prime numbers between 1 and 100. Next, its going to add those number to find the sum of prime numbers between 1 and 100.

# Python Program to find Sum of Prime Numbers from 1 to N minimum = int(input(" Please Enter the Minimum Value: ")) maximum = int(input(" Please Enter the Maximum Value: ")) total = 0 for Number in range (minimum, maximum + 1): count = 0 for i in range(2, (Number//2 + 1)): if(Number % i == 0): count = count + 1 break if (count == 0 and Number != 1): print(" %d" %Number, end = ' ') total = total + Number print("\n\nSum of Prime Numbers from %d to %d = %d" %(minimum, maximum, total))

**OUTPUT**

## Python Program to find Sum of Prime Numbers from 1 to N

This will allows the user to enter Minimum and Maximum values. Next, it will find the sum of prime numbers between Minimum and Maximum values

# Python Program to print Prime Numbers from 1 to N minimum = int(input(" Please Enter the Minimum Value: ")) maximum = int(input(" Please Enter the Maximum Value: ")) total = 0 Number = minimum while(Number <= maximum): 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 = ' ') total = total + Number Number = Number + 1 print("\n\nSum of Prime Numbers from %d to %d = %d" %(minimum, maximum, total))

**OUTPUT**