Python Program to Print all Prime Numbers from 1 to N numbers

 Print all the prime number from 1 to N number

Step to create these program:

  1. First we take the first number as 1
  2. Then we take the second number from the user
  3. Then we iterate the for loop from first to last+1
  4. Then we check the number is greater than 1 
  5. Then we iterate again for loop from 2 to num
  6. Then we check to divide the num from the for loop and check is equal to zero
  7. Other wise print num
  1.  first= 1  
  2. #Take the input from the user:  
  3. last= int(input("Enter the number: "))  
  4.   
  5. for num in range(first,last+ 1):  
  6.    if num > 1:  
  7.        for i in range(2,num):  
  8.            if (num % i) == 0:  
  9.                break  
  10.        else:  

  1.            print(num)  
Output :

Enter the number: 10
2
3
5
7


Next Post Previous Post
1 Comments
  • Vaibhav Chandra
    Vaibhav Chandra March 10, 2021 at 4:39 PM

    i can create your blog more cool like me
    infonexx.blogspot.com
    for free
    i like you post bro

Add Comment
comment url