Week 4 - Quiz (Programming, Datastructures and Algorithms using Python) (NPTEL 2022 - CS26)

 All questions carry equal weightage. All Python code is assumed to be executed using Python3. You may submit as many times as you like within the deadline. Your final submission will be graded.

Note:

  • If the question asks about a value of type string, remember to enclose your answer in single or double quotes.
  • If the question asks about a value of type list, remember to enclose your answer in square brackets and use commas to separate list items.

Consider the following Python function.

def mystery(l,v):
  if len(l) == 0:
    return (v)
  else:
    return (mystery(l[:-1],l[-1]+v))

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

2.5 points
What is the value of triples after the following assignment?
triples = [ (x,y,z) for x in range(2,4) for y in range(2,5) for z in range(5,7) if 2*x*y > 3*z ]
2.5 points
2.5 points
Consider the following dictionary.
runs = {"Test":{"Rahul":[90,14,35],"Kohli":[3,103,73,42],"Pujara":[53,15,133,8]},"ODI":{"Sharma":[37,99],"Kohli":[63,47]}}
Which of the following statements does not generate an error?
 
 
 
 
2.5 points
Assume that actor has been initialized as an empty dictionary:
actor = {}
Which of the following generates an error?
 
 
 
 

Comments

Popular posts from this blog

Week 6 - Quiz (Programming, Datastructures and Algorithms using Python) (NPTEL 2022 - CS26)

Week 7 - Quiz (Programming, Datastructures and Algorithms using Python) (NPTEL 2022 - CS26)