DEV Community

Sivakumar Mathiyalagan
Sivakumar Mathiyalagan

Posted on

Python Exercise

Question:
Given an integer n, return all unique pairs of prime numbers whose sum is equal to n.

CODE:

givenNumber = 70
no2 = 1

while no2 < givenNumber:

    no1 = givenNumber - no2

    num = 1
    count1 = 0

    while num <= no1:
        if no1 % num == 0:
            count1 +=1
        num = num + 1


    num = 1
    count2 = 0

    while num <= no2:
         if no2 % num == 0:
             count2 +=1
         num = num + 1

    if count1 == 2 and count2 ==  2:
         print (no1,no2)


    no2 = no2 + 1
Enter fullscreen mode Exit fullscreen mode

OUTPUT:

Top comments (0)