I am trying to create a simple recursive prime number function.
I am not sure why this is not working. I originally was using remainder division but changed it to integer division.
**** if n ==0: # This runs infinitely,
The recursive call does not seem to roll down.
Output looks like this for the prime number 5 and the not prime number 4
======================
enter a number to check for prime: 5
This is not a Prime number
This is a prime number
This is a prime number
This is a prime number
This is a prime number
The number 5 is True.
==================================
Would you like to check another number for prime? y
enter a number to check for prime: 4
This is not a Prime number
This is a prime number
This is a prime number
This is a prime number
The number 4 is True.
Would you like to check another number for prime?
=========================================
def prime(n):
if n == 0:
print("This is not a Prime number")
answer = 0
if n == 1:
print("This is not a Prime number")
answer = 1
else:
val1 = n // prime(n - 1)
if val1 == 0:
print("This is not a Prime number")
answer = False
else:
print("This is a prime number")
answer = True
return answer