# The Joy of Computing using Python Week 6 : Assignment 1 | NPTEL | [Jan 2023]

## Which of the following is true about recursion?

a. Recursion always performs better than non-recursive code.
b. Recursive code can be reused.
c. The base case is necessary for recursion.
d. Recursive code can be shorter than non-recursive code

b. Recursive code can be reused.
c. The base case is necessary for recursion.
d. Recursive code can be shorter than non-recursive code

a. EJBNPOE
b. FKCORPF
c. HMERTSH
d. HMEQSRH

d. HMEQSRH

## Let L be a list containing different names of movies. Which statement is correct to select a random movie name from that list L?

a. random.choices(L)
b. random.select(L)
c. random.movie(L)
d. random.random(L)

a. random.choices(L)

a. 0
b. 1
c. 2
d. 3

c. 2

## What will be the output of the following code?

```import string
def shift(word,value):

letters = string.ascii_lowercase
new =

for i in range(len(word)):
if word[i] in letters:

index = letters.index(word[i])
new = new + letters[(index+value)%26]

else:
new = new + word[i]

return new

```
a. Shift every letter in a given word by value.
b. Shift every letter in a given word by 1.
c. Shift every letter in a given word by 26.
d. Returns the same word.

a. Shift every letter in a given word by value.

a. PIL
b. Imageview
c. IMG
d. image

a. PIL

a. Commas
b. Colons
c. Semi-colons
d. Slash

a. Commas

## what will be the output of the following program?

```def recursive(num):
if(num==1):
print('*')
return

if(nums%2==0):
print('*'*num)
recursive(num-1)
return

else:
recursive(num-1)
return

recursive(10)

a.
**********
*********
********
*******
******
*****
****
***
**
*

b.
*********
*******
*****
***
*

c. Runs into infinite loop

d.
**********
********
******
****
**
*```

Option d is correct answer

## What will happen if we don’t check for a base case in recursion.

a. The program will run smoothly
b. The program will return a wrong output.
c. The program will enter into an infinite loop.
d. The program will never run.

c. The program will enter into an infinite loop.

## Which of the following is true about recursion?

a. Recursion increases the speed of the program.
b. Recursion decreases the speed of the program.
c. Speed of the program remains the same.
d. Recursion is easier to understand than non-recursive programs.