Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

python question! please show code and steps!! Bonus Question 2 (Ackermann Functi

ID: 3665984 • Letter: P

Question

python question!

please show code and steps!!

Bonus Question 2 (Ackermann Function) [2 points]: The Ackermann function has some interesting theoretical properties because it is not "primitive recursive". It is recursively defined by if m 0 and n 0 A(m, n EA(m 1, l) if m 0 and n 0 A(m 1, A(m, n 1)) The function grows very quickly, for example A(4.2) is about 2 x 10 Implement the Ackermann function 19728 in Python and test for which parameters you can compute the result A (2, 2) Write a recursive function consisting of a single return statement and put it in the file B2 yourmacid.py Add as a comment all the values of m, n for which you are able to compute 40m. n)with Python.

Explanation / Answer

#python program that calculates the Ackerman formula using recursion

#B2_yourmacid.py

#main method definition
def main():

    #set m and n values
    m=2
    n=2
    #call Ackermann(2,2)
    result=Ackermann(m,n)
    #print result
    printf "Ackermann ", result
  
# The method Ackermann that takes m and n as arguments
#returns the result
def Ackermann(m,n):

#check if m is zero
    if m ==0 :
            # return n+1
        return n+1
    #check if m is greater than 0 and n is zero
    elif m>0 and n==0:
        #call Ackermann
        return Ackermann(m-1,1)
    #check if m is greater than 0 and n is greater than 0
    elif m>0 and n>0:
        #call Ackermann
        return Ackermann(m-1, Ackermann(m,n-1))

#call main method  
main()


----------------------------------------------------------------------------------------------------------------

Sampel output:

Ackermann 7

Note : Make sure m=4 and n=2 overloaed the stack operations of the method Ackerman and terminates

the program since the result of the function cannot be stored double variable.

Ackerman(4,2) resutls in a number that has 19729 digits. so make sure do not give 4 and 2 as input arguments.