- To print prime numbers between 1 & N

User Input: 12

Output: 2,3,5,7,11

```
num=int(input("Enter any +ve number : "))
def prime(n) :
if n<2 : return 0
for i in range(2,int(n/2)+1) :
if n%i==0 : return 0
return 1
print("Your prime numbers between 1 & ",num," are :",end=" ")
for i in range(2,num) :
if(prime(i)) :
print(i,end=" ")
```

Enter any +ve number : 20 Your prime numbers between 1 & 20 are : 2 3 5 7 11 13 17 19Program

number

You should know first :

**Prime numbers: ** Numbers greater than 1 & have only 2 factors ( 1 and itself )

Main Logic to check prime :

```
def prime(n) :
if n<2 : return 0
for i in range(2,int(n/2)+1) :
if n%i==0 : return 0
return 1
```

We are running the loop `n/2`

Since, any number can have only factors under its half, except itself

To print all primes :

```
for i in range(2,num) :
//check every number for prime [ if prime(i) : ], if prime then print the number
}
```

Concept
Coming Soon !

QuickTutorial

The best preparation for good work tomorrow is to do good work today.