**1) What does f(31415927) return, for the following function definition?**

def f(x): d=0 while x > 1: (x,d) = (x/2,d+1) return(d)

Answer(s) : 25

**2) What is the value of h(6,8) for the function below?**

def h(m,n): ans = 1 while (n > 0): (ans,n) = (ans*m,n-2) return(ans)

Answer(s) : 1296

**3) **

def h(n): f = 0 for i in range(1,n+1): if n%i == 0: f = f + 1 return(f == 2)

The function h(n) given above returns True for a positive number n whenever:

(A) n is a multiple of 2

(B) n is a composite number

(C) n is a prime number

(D) n has an even number of factors

Answer(s) : (C) n is a prime number

**4) Consider the following function f **

def f(m): if m == 0: return(1) else: return(m*f(m-1))

(A) The function always terminates with f(n) = n

(B) The function always terminates with f(n) = factorial of n

(C) The function terminates for non-negative n with f(n) = n

(D) The function terminates for non-negative n with f(n) = factorial of n

Answer(s) : (D) The function terminates for non-negative n with f(n) = factorial of n

## 6 Comments

## himanshu · February 19, 2018 at 1:03 PM

Sir 21st is last day for assigment 1 and 2 of IMAD plz help

## Yash Sodha · February 20, 2018 at 4:25 PM

posted

## HARISH · February 19, 2018 at 1:22 PM

Please post the week 2 solutions

## Yash Sodha · February 20, 2018 at 4:24 PM

Hey! Posted

## Anurag Kothare · February 20, 2018 at 4:41 AM

In question 1 how you are getting 25?

I am getting 24.

## Yash Sodha · February 20, 2018 at 4:24 PM

Try executing it in Python!