Question

# Please do it in Python Write the simplest program that will demonstrate iteration vs recursion using...

Write the simplest program that will demonstrate iteration vs recursion using the following guidelines -

1. Write two primary helper functions - one iterative (IsArrayPrimeIter) and one recursive (IsArrayPrimeRecur) - each of which
1. Take the array and its size as input params and return a bool.
2. Print out a message "Entering <function_name>" as the first statement of each function.
3. Perform the code to test whether every element of the array is a Prime number.
4. Print out a message "Leaving <function_name>" as the last statement before returning from the function.
5. Remember - there will be nested loops for the iterative function and there can be no loops at all in the recursive function. You will need to define other helper functions to make the recursive method work.
6. Remember - replace <function_name> with the actual name of each function.
7. You can create secondary helper functions if you need, but only the primary helper functions can be invoked from 'main'.
8. Hint - try to complete your iterative code first and then convert it piece by piece to the recursive code.
1. Ask the user for the number of elements, not to exceed SORT_MAX_SIZE = 16 (validate input).
2. Create an array based on the size input provided by the user.
3. Get the input in a loop, validating that the integers input by the user are between 1 and 99, both inclusive
4. Make a call to the primary iterative function passing the array and its size.
5. If every member is a Prime, then the program should print out 'Prime Array using iteration', otherwise print out 'Not a Prime Array using iteration'.
6. Then make a call to the primary recursive function passing the array and its size.
7. If every member is a Prime, then the program should print out 'Prime Array using recursion', otherwise print out 'Not a Prime Array using recursion'.
8. If your functions are coded correctly, both should come up with the same answer, except you should have lots more output statements using recursion.
9. There is no sample output - you are allowed to provide user interactivity as you see fit but programs will be graded for clarity of interaction.
3. You can use language native arrays - DO NOT USE VECTORS, COLLECTIONS, SETS, BAGS or any other data structures from your programming language.
4. There will be only one code file in your submission.
5. Remember to take multiple screenshots so that they are clearly readable without needing to zoom in.
6. For documentation, include your name block as well pre/post and pseudocode for the functions only.
7. Upload your code file and the screenshots in one zip file. Do not include anything else.

• 25 pts - EXE works from your code as explained above without needing any code change
• 15 pts - for the main
• 25 pts - the IsArrayPrimeIter function
• 35 pts - the IsArrayPrimeRecur function

I understand most of this information is more suitable to C++ but our instructor wants us to modify it to do it in Python. As long as you fufill the parameters the best you can in Python and works that all I want. Thank you

Program:

``````# function is used to check whether a given number or not using iteration

def isPrime(n):
if n <= 1:
return False
for i in range(2, n):
if n % i == 0:
return False;
return True

# function is used to check whether a given list has all prime numbers or not using iteration

def check_list_prime_iteration(arr,le):
count=0
for i in arr:
if(isPrime(i)):
count=count+1
if(count==le):
return True
else:
return False

# function is used to check whether a given list has all prime numbers or not using recusrion

def check_list_prime_recursion(arr,le):
count=0
for i in arr:
if(isPrime_Rec(i)):
count=count+1
if(count==le):
return True
else:
return False

# function is used to check whether a given number or not using recusrion

def isPrime_Rec(n, i = 2):
if (n <= 2):
return True if(n == 2) else False
if (n % i == 0):
return False
if (i * i > n):
return True
return isPrime_Rec(n, i + 1)

# List to store values
l=[]
i=1
# input taking
n=int(input("Enter size of an Array"))
while(i<=n):
input_value=int(input("Enter number"))
if(input_value>=1 and input_value<=99):
l.append(input_value)
else:
print("please enter valid input between 1 and 99")
i=i-1
i=i+1
# Final list after validation
print("Array List",l)

if check_list_prime_iteration(l,len(l)):
print("Prime Array using iteration")
else:
print("Not a Prime Array using iteration")

if check_list_prime_recursion(l,len(l)):
print("Prime Array using recursion")
else:
print("Not a Prime Array using recursion")``````

Output:

#### Earn Coins

Coins can be redeemed for fabulous gifts.