Week 4 - Quiz (Programming, Datastructures and Algorithms using Python) (NPTEL 2022 - CS26)
Get link
Facebook
X
Pinterest
Email
Other Apps
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.
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 ]
Feedback:
triples = []
for x in range(2,4): # x = 2,3
for y in range(2,5): # y = 2,3,4
for z in range(5,7): # z = 5,6
if 2*x*y > 3*z:
triples.append((x,y,z))
Output: [(2, 4, 5), (3, 3, 5), (3, 4, 5), (3, 4, 6)]
Suppose u and v both denote sets in Python. Under what condition can we guarantee that u-(v-u) == u ? The sets u and v should be disjoint. The set u should be a subset of the set v The set v should be a subset of the set u This is true for any u and v . Feedback: v-u has no elements from u , so u-(v-u) removes nothing from u and is hence always equal to u . Accepted Answers: D This is true for any u and v . 2.5 points Suppose u and v both denote sets in Python. and u|v != u^v . What can we conclude about u and v ? The sets u and v should overlap. The set v should be a subset of the set u . The set u should be a subset of the set v . This is true for...
One of the following 10 statements generates an error. Which one? (Your answer should be a number between 1 and 10.) x = [1,"abcd",2,"efgh",[3,4]] # Statement 1 y = x[0:6] # Statement 2 z = x # Statement 3 w = y # Statement 4 x[1] = x[1][0:3] + 'd' # Statement 5 y[2] = 4 # Statement 6 z[1][1:3] = 'yzw' # Statement 7 z[0] = 0 # Statement 8 w[4][0] = 1000 # Statement 9 a = (x[4][1] == 4) # Statement 10 Accepted Answers: 7 (Type: Numeric) 7 2.5 points 2.5 points Consider the following lines of Python code. x = [423,'b',37,'f'] u = x[1:] y = u w = x u = u[0:] u[1] = 53 x[2] = 47 After these execute, which of the following is correct? x[2] == 47, y[1] == 37, w[2] == 47, u[1] == 53 x[2] == 47, y[1] == 53, w[2] == 47, u[1] == 53 x[2] == 47, y[1] == 37, w[2] == 37, u[1] ==...
Comments
Post a Comment