plus2net.com offers FREE online classes on Basics of Python for selected few visitors.

Read more on course content , Details about the Program.

Prime numbers are having only two factors, one is 1 and other one is the number itself. Read more on course content , Details about the Program.

These are the first 5 prime numbers

Prime numbers are divisible by exactly two natural numbers.

### Video Tutorial on Prime Numbers

Here is the code to get prime numbers up to some value.

```
#n=int(input("Enter a number : "))
n=50 # change this value
for i in range(2,n+1):
flag=0
for j in range(2,int(i/2)+1):
if(i%j==0):
flag=1
break
if(flag==0):
print(i,end=', ')
```

Output
`2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47,`

In above code we can remove the comment at first line and add comment to 2Factors of a number

This code will generate 10 Prime numbers, you can change the value to get more prime numbers.

```
n=1
i=2
while ( n <= 10): # change this value for more numbers
b=0
for j in range(2,int(i/2)+1):
if(i%j==0):
b=1
break
if(b==0):
print(i,end=', ')
n=n+1
i=i+1
```

Output
`2, 3, 5, 7, 11, 13, 17, 19, 23, 29, `

```
n=int(input("Enter number :"))
for i in range(2,n):
if(n%i==0):
print("composite/Not a prime number")
break
else:
print("prime number")
```

All Sample codes

Fibonacci series Factors of a number Factorial of a number Armstrong Number

This article is written by **plus2net.com** team.

Post your comments , suggestion , error , requirements etc here

Python Video Tutorials

Python SQLite Video Tutorials

Python MySQL Video Tutorials

Python Tkinter Video Tutorials