#### Programming, Data Structures And Algorithms Using Python - Assignment 1 | NPTEL |Answer with Explanation

"Unlock the power of Python with our Programming, Data Structures and Algorithms ! Test your knowledge with first assignment, featuring multiple choice questions on the fundamentals of Python programming : Introduction"<.p>

## What is the value of f(2343) for the function below?

def f(x):

d=0

y=1

while y <= x:

d=d+1

y=y*3

return(d)

## Answer

8

y = 1 < 2343

=> d = 0 + 1 = 1

y = 1 * 3 = 3

3 < 2343

=> d = 1 + 1 = 2

y = 3 * 3 = 9

9 < 2343

=> d = 2 + 1 = 3

y = 9 * 3 = 27

27 < 2343

=> d = 3 + 1 = 4

=> y = 27 * 3 = 81

81 < 2343

=> d = 4 + 1 = 5

=> y = 81 * 3 = 243

243 < 2343

=> d = 5 + 1 = 6

=> y = 243 * 3 = 729

729 < 2343

=> d = 6 + 1 = 7

y = 729 * 3 = 2187

2187 < 2343

=> d = 7 + 1 = 8

y = 2187 * 3 = 6561

6561 > 2343

Hence d = 8

f(2343) Returns 8
value of f(2343) = 8

## What is h(53)-h(52), 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)

## Answer

5

## For what integer value n would g(92,n) return 13?

def g(m,n):

res = 0

while m >= n:

res = res+1

m = m-n

return(res)

## Answer

7

## 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, assuming we always pass an integer argument to mys?

a. The function always terminates with mys(n) = factorial of n

b. The function always terminates with mys(n) = 1+2+...+n

c. The function terminates for non-negative n with mys(n) = factorial of n

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

## Answer

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

The correct statement is "The function terminates for positive n with mys(n) = factorial of n"
This is because the function uses recursion to calculate the factorial of the input number. The recursion stops when the input number reaches 1, and then it starts returning the calculated factorial. If the input number is 0 or negative, it will not terminate as the recursion never stops.

Disclaimer:

"This page contains multiple choice questions (MCQs) related to Programming, Data Structures And Algorithms Using Python. The answers to these questions are provided for educational and informational purposes only.These answers are provided only for the purpose to help students to take references. This website does not claim any surety of 100% correct answers. So, this website urges you to complete your assignment yourself."

## 0 Comments