Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Function 1 - Check the existence of a prime between the 2 arguments
- def checkPrimeExistence(n1, n2):
- MAX = max(n1, n2)
- MIN = min(n1, n2)
- exists = False
- solution = 0
- for n in range(MIN, MAX+1):
- isPrime = True
- for i in range(2, int(n/2)):
- if n % i == 0:
- isPrime = False
- break
- if isPrime:
- exists = True
- solution = n
- if exists:
- print(str(MIN) + " - " + str(MAX) + " ----> " + str(solution))
- return True
- else:
- print("**********************************************************")
- print("There is no prime between " + str(MIN) + " and " + str(MAX))
- print("**********************************************************")
- return False
- # MAIN FUNCTION
- limit = 300
- for i in range(2, limit):
- n1 = i ** 2
- n2 = (i+1) ** 2
- flag = checkPrimeExistence(n1, n2)
- if flag == False:
- # This means that there is no prime between the 2 limits
- print("Finally, there is no prime between " + str(n1) + "^2 and " + str(n2) + "^2")
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement