Prime number series in python with algorithm


Prime number series in python with algorithm

Q):Implement python script to generate prime number series up to n

Aim: To generate prime number series up to n 

Algorithm:
step 1: Start
step2: Declare lower variable and read 
step 3: Declare higher variable and read.
step 4: In n for loop take the range of value from lower to higher .
step 5 : Check for the condition n > 1
step 6: If the condition is true go to the i for loop otherwise take the next iteration 
step 7: In i for loop check the condition n % i = 0
step 8: if the condition is true then break the loop otherwise print that n value
step 9: end.
 
Source code:
 
 lower = int(input(“enter lower range:”))
higher = int(input("enter higher range:"))
for num in range(lower,higher + 1):
   # prime numbers are greater than 1 
  if num > 1:
       for i in range(2,num):
           if (num % i) == 0:
               break     
        else:
           print(num)
 
 
Output:
enter lower range:0
enter higher range:50
2
3
5
7
11
13
17
19
23
29
31
37
41
43
47

Process finished with exit code 0

prime number series in python with algorithm

Have any Question or Comment?

Leave a Reply

Your email address will not be published. Required fields are marked *

Domain & free Hosting

Categories

You have successfully subscribed to myprogrammingschool

There was an error while trying to send your request. Please try again.

My Programming School will use the information you provide on this form to be in touch with you and to provide updates and marketing.