1 Objective Questions |
1 Objective Questions |
2 ------------------- |
2 ------------------- |
3 |
3 |
4 1. If ``a = [1, 1, 2, 3, 3, 5, 5, 8]``. What is set(a) |
4 1. which default argument, when used with ``@interact`` gives a slider |
|
5 starting at 0 and ending in 10 |
5 |
6 |
6 a. set([1, 1, 2, 3, 3, 5, 5, 8]) |
7 a. (0..11) |
7 #. set([1, 2, 3, 5, 8]) |
8 #. range(0, 11) |
8 #. set([1, 2, 3, 3, 5, 5]) |
9 #. [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] |
9 #. Error |
10 #. (0..10) |
10 |
11 |
11 Answer: set([1, 2, 3, 5, 8]) |
12 Answer: (0..10) |
12 |
13 |
13 2. ``a = set([1, 3, 5])``. How do you find the length of a? |
14 2. What is the input widget resulted by using ``n = [2, 4, 5, 9]`` in the |
|
15 default arguments along with ``@interact`` |
14 |
16 |
15 Answer: len(a) |
17 a. input field |
|
18 #. set of buttons |
|
19 #. slider |
|
20 #. None |
16 |
21 |
17 3. ``a = set([1, 3, 5])``. What does a[2] produce? |
22 Answer: set of buttons |
18 |
23 |
19 a. 1 |
24 3. what is the type of ``n`` in the following function:: |
20 #. 3 |
|
21 #. 5 |
|
22 #. Error |
|
23 |
25 |
24 Answer: Error |
26 @interact |
|
27 def f(n=2.5): |
|
28 # do something with n |
25 |
29 |
26 4. ``odd = set([1, 3, 5, 7, 9])`` and ``squares = set([1, 4, 9, 16])``. What |
30 a. int |
27 is the value of ``odd | squares``? |
31 #. float |
|
32 #. string |
|
33 #. complex |
28 |
34 |
29 Answer: set([1, 3, 4, 5, 7, 9, 16]) |
35 Answer: float |
30 |
36 |
31 5. ``odd = set([1, 3, 5, 7, 9])`` and ``squares = set([1, 4, 9, 16])``. What |
|
32 is the value of ``odd - squares``? |
|
33 |
|
34 Answer: set([3, 5, 7]) |
|
35 |
|
36 6. ``odd = set([1, 3, 5, 7, 9])`` and ``squares = set([1, 4, 9, 16])``. What |
|
37 is the value of ``odd ^ squares``? |
|
38 |
|
39 Answer: set([3, 4, 5, 7, 16]) |
|
40 |
|
41 7. ``odd = set([1, 3, 5, 7, 9])`` and ``squares = set([1, 4, 9, 16])``. What |
|
42 does ``odd * squares`` give? |
|
43 |
|
44 a. set([1, 12, 45, 112, 9]) |
|
45 #. set([1, 3, 4, 5, 7, 9, 16]) |
|
46 #. set([]) |
|
47 #. Error |
|
48 |
|
49 Answer: Error |
|
50 |
|
51 8. ``a = set([1, 2, 3, 4])`` and ``b = set([5, 6, 7, 8])``. What is ``a + b`` |
|
52 |
|
53 a. set([1, 2, 3, 4, 5, 6, 7, 8]) |
|
54 #. set([6, 8, 10, 12]) |
|
55 #. set([5, 12, 21, 32]) |
|
56 #. Error |
|
57 |
|
58 9. ``a`` is a set. how do you check if if a varaible ``b`` exists in ``a``? |
|
59 |
|
60 Answer: b in a |
|
61 |
|
62 10. ``a`` and ``b`` are two sets. What is ``a ^ b == (a - b) | (b - a)``? |
|
63 |
|
64 a. True |
|
65 #. False |
|
66 |
|
67 Answer: False |
|
68 |
|
69 |
|
70 Larger Questions |
|
71 ---------------- |
|
72 |
|
73 1. Given that mat_marks is a list of maths marks of a class. Find out the |
|
74 no.of duplicates marks in the list. |
|
75 |
|
76 Answer:: |
|
77 |
|
78 unique_marks = set(mat_marks) |
|
79 no_of_duplicates = len(mat_marks) - len(unique_marks) |
|
80 |
|
81 2. Given that mat_marks is a list of maths marks of a class. Find how many |
|
82 duplicates of each mark exist. |
|
83 |
|
84 Answer:: |
|
85 |
|
86 marks_set = set(mat_marks) |
|
87 for mark in marks_set: |
|
88 occurences = mat_marks.count(mark) |
|
89 print occurences - 1, "duplicates of", mark, "exist" |
|
90 |
|