Q. Write a method in Python to find and display the prime numbers between 2 to N. Pass argument to the method.


Answer =


def check_primeAll (N) :
    count = 0
    for i in range(2, N + 1) :
        count = 0
        for j in range(2,i) :
            if i % j == 0 :
                count = 1
        if count == 0 :
            print(i)


Output :-

>>> check_primeAll (10)
2
3
5
7

>>>

>>> check_primeAll (50)
2
3
5
7
11
13
17
19
23
29
31
37
41
43
47

>>>

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post