Programming, Data Structures And Algorithms Using Python - Week 4 Quiz | NPTEL | [Jan 2023]

Programming, Data Structures And Algorithms Using Python - Week 4 Quiz | NPTEL Jan 2023 | Answer with Explanation

 Programming, Data Structures And Algorithms Using Python - Week 4 Quiz   NPTEL   [Jan 2023]

Consider the following Python function.

def mystery(l):
  if (l == []):
    return(l)
  else:
    mid = len(l)//2
    if (len(l)%2 == 0):
      return l[mid-1:mid+1] + mystery(l[:mid-1]+l[mid+1:])
    else:
      return l[mid:mid+1] + mystery(l[:mid]+l[mid+1:])

What does mystery([22,14,19,65,82,55]) return?

Answer

[19, 65, 14, 82, 22, 55]

What is the value of triples after the following assignment?
triples = [ (x,y,z) for x in range(1,4) for y in range(2,5) for z in range(5,8) if x+y > z ]

Answer

[(2, 4, 5), (3, 3, 5), (3, 4, 5), (3, 4, 6)]

Consider the following dictionary.
marks = {"Quizzes":{"Mahesh":[3,5,7,8],"Suresh":[9,4,8,8],"Uma":[9,9,7,6]},"Exams":{"Mahesh":[37],"Uma":[36]}}
Which of the following statements does not generate an error?

a. marks["Exams"]["Suresh"].extend([44])
b. marks["Exams"]["Suresh"] = [44]
c. marks["Exams"]["Suresh"].append(44)
d. marks["Exams"]["Suresh"][0:] = [44]
Answer

b. marks["Exams"]["Suresh"] = [44]

Option 1: Output KeyError: 'Suresh'

Option 2:Output {'Quizzes': {'Mahesh': [3, 5, 7, 8], 'Suresh': [9, 4, 8, 8], 'Uma': [9, 9, 7, 6]}, 'Exams': {'Mahesh': [37], 'Uma': [36], 'Suresh': [44]}}

Option 3: Output KeyError: 'Suresh'

Option 4: Output KeyError: 'Suresh'

Assume that actor has been initialized as an empty dictionary:
actor = {}
Which of the following generates an error?

a. actor["Star Wars"] = ["Rey","Ridley"]
b. actor["Star Wars, Rey"] = "Ridley"
c. actor[["Star Wars", "Rey"]] = "Ridley"
d. actor[("Star Wars", "Rey")] = "Ridley"
Answer

c. actor[["Star Wars", "Rey"]] = "Ridley"

Option 1: Output
{'Star Wars': ['Rey', 'Ridley']}

Option 2: Output
{'Star Wars, Rey': 'Ridley'}

Option 3: Output
TypeError: unhashable type: 'list'

Option 4: Output
{('Star Wars', 'Rey'): 'Ridley'}

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."

Programming, Data Structures And Algorithms Using Python,NPTEL, Week 4 Quiz Assignment 1 [Jan 2023],noc23_cs15

Post a Comment

0 Comments