# Programming, Data Structures And Algorithms Using Python - Assignment 1 | NPTEL | [Jan 2023]

#### 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)

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

5

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