# Are there 5 consecutive primes?

Jul 31st, 2021
830
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. # Function 1 - isPrime
2. def isPrime(n):
3.     if n != int(n) or  n <= 1:
4.         print("Error while using function '" + isPrime.__name__ + "'")
5.         return -1000
6.     if n == 1 or n == 2:
7.         return True
8.     for i in range(2, int(n/2)):
9.         if n % i == 0:
10.             return False
11.     return True
12.
13. # Function 2 - Create pentada
14. def createPentada(n):
15.     if n % 10 != 0:
16.         print("Error while using function '" + isPrime.__name__ + "'")
17.         return -1000
18.     return [n+1, n+3, n+5, n+7, n+9]
19.
20. # Function 3 - Solve
21. def solve(LIMIT):
22.     for n in range(0, LIMIT, 10):
23.         pentada = createPentada(n)
24.         hits = 0
25.         for x in pentada:
26.             flag2 = isPrime(x)
27.             if flag2 == True:
28.                 hits += 1
29.             else:
30.                 print("Number that breaks the sequence = " + str(x))
31.                 break
32.         if hits == 5:
33.             return pentada
34.
35.
36. # MAIN FUNCTION
37. LIMIT = 10**5
38. print(solve(LIMIT))
39.
RAW Paste Data