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...
Given the following permutation of a,b,c,d,e,f,g,h,i,j, what is the previous permutation in lexicographic (dictionary) order? Write your answer without any blank spaces between letters. fjadchbegi Feedback: Invert the algorithm given in the video. Look for the longest suffix in increasing order, here begi . The letter before is h . Replace by the next smallest letter in the suffix, g and arrange the remaining letters in descending order, to get giheb . So the final answer is fjadcgiheb . Accepted Answers: fjadcgiheb (Type: Regex Match) [ ]*fjadcgiheb[ ]* (Type: Regex Match) [ ]*\'fjadcgiheb\'[ ]* (Type: Regex Match) [ ]*\"fjadcgiheb\"[ ]* 2.5 points 2.5 points Assume we have defined a class Node that implements user defined lists of numbers. Each object node of type Node has two attributes node.value and node.next with the usual interpretation. We want to add a function sum() to the class Node which will compute the sum of values ...
Comments
Post a Comment