Define a method isprime(int) to accept an integer and return true if it is prime else return false. Write a main method to input two integers and check whether they are Twin Prime numbers or not. Twin prime are those numbers which are prime and having a difference of two (2) between the two prime numbers. E.g. (3,5), (5, 7), (11, 13), (17, 19), (29, 31)...
Answers
Answered by
1
Python Code:
def isprime(int):
factors = [ ]
for number in range(2, int):
if int%number == 0:
factors.append(number)
if len(factors) <= 0:
print(f’{int} is a prime number.’)
else:
print(f’{int} is a composite number.’)
number = int(input(‘enter the number - ’))
isprime(number)
Method/Algorithm of twin prime numbers:
1. Input the numbers.
2. Check if the difference between them is two or not.
3. if the difference is two, then check for the prime of both the numbers.
4. If both are prime then print/ return True.
5. If either or both of them are composite then print/ return False.
6. If the difference is not true then print/ return false.
Similar questions