Q. Look at compute numbers again:

 

compute (1) = 1

compute (N) = compute (N-1) + 2N-1

 

Which Python function below successfully implements this definition?

 

(a)

def compute(N):

    if N<1:

        return 1

    else:

        return N. N

 

(b)

def compute(N) :

    if N ==1:

        return 1

    else:

        return compute(N-1) + 2 *N – 1

 

(c)

def compute(N) :

    if N = 1:

        return 1

    else:

        return compute(N-1) + 2 *N – 1

 

(d)

def compute(N) :

    if N = 1:

        return 1

    else:

        return compute(N)

 

 

Answer =

Option (b) is successfully implements this definition.

 

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post