0% found this document useful (0 votes)
55 views1 page

Programming, Data Structures and Algorithms Using Python - Unit 10 - Week 4 Quiz

Uploaded by

Arunkumar M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views1 page

Programming, Data Structures and Algorithms Using Python - Unit 10 - Week 4 Quiz

Uploaded by

Arunkumar M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

9/20/22, 8:53 PM Programming, Data Structures And Algorithms Using Python - - Unit 10 - Week 4 Quiz

Week 4 Quiz
The due date for submitting this assignment has passed.
Due on 2022-08-24, 23:59 IST.
Score: 10/10=100%

Assignment submitted on 2022-08-18, 21:09 IST


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):

if l == []:

return(l)
else:

return(mystery(l[1:])+l[:1])

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

Yes, the answer is correct.


Score: 2.5

Feedback:
Elements are moved from the beginning of the list to the end, so the list gets reversed.
Accepted Answers:
(Type: Regex Match) [ ]*[[ ]*55[ ]*,[ ]*82[ ]*,[ ]*65[ ]*,[ ]*19[ ]*,[ ]*14[ ]*,[ ]*22[ ]*][ ]*
What is the value of pairs after the following assignment? 2.5 points

pairs = [ (x,y) for x in range(4,1,-1) for y in range(5,1,-1) if (x+y)%3 == 0 ]

Yes, the answer is correct.


Score: 2.5

Feedback:
All pairs (i,j) with i ∈ {4,3,2}, j ∈ {5,4.3,2} such that i + j is a multiple of 3,
Accepted Answers:
(Type: Regex Match) [ ]*[[ ]*\([ ]*4[ ]*,[ ]*5[ ]*\)[ ]*,[ ]*\([ ]*4[ ]*,[ ]*2[ ]*\)[ ]*,[ ]*\([ ]*3[ ]*,[ ]*3[ ]*\)[ ]*,[ ]*\([ ]*2[ ]*,[ ]*4[ ]*\)[ ]*][ ]*
Consider the following dictionary. 2.5 points2.5 points

wickets = {"Tests":{"Bumrah":[3,5,2,3],"Shami":[4,4,1,0],"Ashwin":[2,1,7,4]},"ODI":{"Bumrah":[2,0],"Sham
i":[1,2]}}

Which of the following statements does not generate an error?

 wickets["ODI"]["Ashwin"][0:] = [4,4]
 wickets["ODI"]["Ashwin"].extend([4,4])
 wickets["ODI"]["Ashwin"] = [4,4]
 wickets["ODI"]["Ashwin"] = wickets["ODI"]["Ashwin"] + [4,4]
Yes, the answer is correct.
Score: 2.5

Feedback:
Direct assignment to a new key adds a value. All other updates result in KeyError.
Accepted Answers:
wickets["ODI"]["Ashwin"] = [4,4]
Assume that hundreds has been initialized as an empty dictionary: 2.5 points

hundreds = {}

Which of the following generates an error?

 hundreds["Tendulkar, international"] = 100


 hundreds["Tendulkar"] = {"international":100}
 hundreds[("Tendulkar","international")] = 100
 hundreds[["Tendulkar","international"]] = 100
Yes, the answer is correct.
Score: 2.5

Feedback:
Dictionary keys must be immutable values.
Accepted Answers:
hundreds[["Tendulkar","international"]] = 100

https://onlinecourses.nptel.ac.in/noc22_cs70/unit?unit=57&assessment=126 1/1

You might also like