NPTEL Programming ,Data structure & Algorithms using Python Week1 Quiz Solutions 2021 | Swayam

 


  

    

 

1) What is the value of f(846) for the function below?

def f(x):

    d=0

    y=1

    while y <= x:

        d=d+1

        y=y*3

    return(d)

Ans: 7

 

2)What is h(41)-h(40), given the definition of h below?

def h(n):

    s = 0

    for i in range(1,n+1):

        if n%i > 0:

           s = s+1

    return(s)

Ans: 7

3)For what value of n would g(57,n) return 7?

def g(m,n):

    res = 0

    while m >= n:

        res = res+1

        m = m-n

    return(res)

Ans: 8

4) Consider the following function mys:

def mys(m):

    if m == 1:

        return(1)

    else:

        return(m*mys(m-1))

 

Which of the following is correct?

Ans)

The function terminates for positive n with mys(n) = factorial of n

No comments:

Powered by Blogger.