-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeek 4 : Quiz
More file actions
41 lines (26 loc) · 1.18 KB
/
Week 4 : Quiz
File metadata and controls
41 lines (26 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
1) 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?
Ans:- [55, 82, 65, 19, 14, 22]
2) What is the value of pairs after the following assignment?
pairs = [ (x,y) for x in range(4,1,-1) for y in range(5,1,-1) if (x+y)%3 == 0 ]
Ans:- [(4, 5), (4,2), (3, 3), (2, 4)]
3) Consider the following dictionary.
wickets = {"Tests":{"Bumrah":[3,5,2,3],"Shami":[4,4,1,0],"Ashwin":[2,1,7,4]},"ODI":{"Bumrah":[2,0],"Shami":[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]
Ans:-wickets["ODI"]["Ashwin"] = [4,4] (C)
4) Assume that hundreds has been initialized as an empty dictionary: hundreds = {}
Which of the following generates an error?
hundreds["Tendulkar, international"] = 100
hundreds["Tendulkar"] = {"international":100}
hundreds[("Tendulkar","international")] = 100
hundreds[["Tendulkar","international"]] = 100
Ans:- hundreds[["Tendulkar","international"]] = 100 (D)