author | Nishanth <nishanth@fossee.in> |
Tue, 12 Oct 2010 11:26:09 +0530 | |
changeset 334 | 4b1e81da1c80 |
parent 296 | 641a6ee868c0 |
child 335 | d5248a15274c |
permissions | -rw-r--r-- |
296
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
1 |
Objective Questions |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
2 |
------------------- |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
3 |
|
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
4 |
1. If ``a = [1, 1, 2, 3, 3, 5, 5, 8]``. What is set(a) |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
5 |
|
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
6 |
a. set([1, 1, 2, 3, 3, 5, 5, 8]) |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
7 |
#. set([1, 2, 3, 5, 8]) |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
8 |
#. set([1, 2, 3, 3, 5, 5]) |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
9 |
#. Error |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
10 |
|
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
11 |
Answer: set([1, 2, 3, 5, 8]) |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
12 |
|
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
13 |
2. ``a = set([1, 3, 5])``. How do you find the length of a? |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
14 |
|
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
15 |
Answer: len(a) |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
16 |
|
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
17 |
3. ``a = set([1, 3, 5])``. What does a[2] produce? |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
18 |
|
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
19 |
a. 1 |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
20 |
#. 3 |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
21 |
#. 5 |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
22 |
#. Error |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
23 |
|
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
24 |
Answer: Error |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
25 |
|
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
26 |
4. ``odd = set([1, 3, 5, 7, 9])`` and ``squares = set([1, 4, 9, 16])``. What |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
27 |
is the value of ``odd | squares``? |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
28 |
|
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
29 |
Answer: set([1, 3, 4, 5, 7, 9, 16]) |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
30 |
|
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
31 |
5. ``odd = set([1, 3, 5, 7, 9])`` and ``squares = set([1, 4, 9, 16])``. What |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
32 |
is the value of ``odd - squares``? |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
33 |
|
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
34 |
Answer: set([3, 5, 7]) |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
35 |
|
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
36 |
6. ``odd = set([1, 3, 5, 7, 9])`` and ``squares = set([1, 4, 9, 16])``. What |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
37 |
is the value of ``odd ^ squares``? |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
38 |
|
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
39 |
Answer: set([3, 4, 5, 7, 16]) |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
40 |
|
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
41 |
7. ``odd = set([1, 3, 5, 7, 9])`` and ``squares = set([1, 4, 9, 16])``. What |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
42 |
does ``odd * squares`` give? |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
43 |
|
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
44 |
a. set([1, 12, 45, 112, 9]) |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
45 |
#. set([1, 3, 4, 5, 7, 9, 16]) |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
46 |
#. set([]) |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
47 |
#. Error |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
48 |
|
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
49 |
Answer: Error |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
50 |
|
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
51 |
8. ``a = set([1, 2, 3, 4])`` and ``b = set([5, 6, 7, 8])``. What is ``a + b`` |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
52 |
|
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
53 |
a. set([1, 2, 3, 4, 5, 6, 7, 8]) |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
54 |
#. set([6, 8, 10, 12]) |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
55 |
#. set([5, 12, 21, 32]) |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
56 |
#. Error |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
57 |
|
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
58 |
9. ``a`` is a set. how do you check if if a varaible ``b`` exists in ``a``? |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
59 |
|
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
60 |
Answer: b in a |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
61 |
|
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
62 |
10. ``a`` and ``b`` are two sets. What is ``a ^ b == (a - b) | (b - a)``? |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
63 |
|
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
64 |
a. True |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
65 |
#. False |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
66 |
|
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
67 |
Answer: False |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
68 |
|
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
69 |
|
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
70 |
Larger Questions |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
71 |
---------------- |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
72 |
|
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
73 |
1. Given that mat_marks is a list of maths marks of a class. Find out the |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
74 |
no.of duplicates marks in the list. |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
75 |
|
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
76 |
Answer:: |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
77 |
|
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
78 |
unique_marks = set(mat_marks) |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
79 |
no_of_duplicates = len(mat_marks) - len(unique_marks) |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
80 |
|
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
81 |
2. Given that mat_marks is a list of maths marks of a class. Find how many |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
82 |
duplicates of each mark exist. |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
83 |
|
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
84 |
Answer:: |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
85 |
|
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
86 |
marks_set = set(mat_marks) |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
87 |
for mark in marks_set: |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
88 |
occurences = mat_marks.count(mark) |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
89 |
print occurences - 1, "duplicates of", mark, "exist" |
641a6ee868c0
made the script writing_python_scripts into new form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
90 |