summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--input_output.rst106
-rw-r--r--sets.rst91
2 files changed, 197 insertions, 0 deletions
diff --git a/input_output.rst b/input_output.rst
index 04969a2..4af7aa0 100644
--- a/input_output.rst
+++ b/input_output.rst
@@ -180,3 +180,109 @@ Thankyou
Internal Reviewer 1 :
Internal Reviewer 2 :
External Reviewer :
+
+Questions
+=========
+
+ 1. ``a = 2.5``. What is the output of ``print "a is %d"%(a)``
+
+ a. a is 2.5
+ #. a is 2.0
+ #. 2.0
+ #. a is 2
+
+ Answer: a is 2
+
+ 2. What does ``print "This is", "a line ", "with spaces"`` print?
+
+ a. This is a line with spaces
+ #. This is a line with spaces
+ #. This is a line with spaces
+ #. This is a line with spaces
+
+ Answer: This is a line with spaces
+
+ 3. What does ``print "%2.5f"%(1.2)`` print?
+
+ a. 1.2
+ #. 1.20
+ #. 1.20000
+ #. 00001.2
+
+ Answer: 1.20000
+
+ 4. What is the output of the following code::
+
+ for i in range(1,10,2):
+ print i,
+
+ Answer::
+
+ 1 3 5 7 9
+
+ 5. ``a = 2`` and ``b = 4.5``. What does ``print "a is %d and b is %2.1f"%(b, a)``
+ print?
+
+ a. a is 2 and b is 4.5
+ #. a is 4 and b is 2
+ #. a is 4 and b is 2.0
+ #. a is 4.5 and b is 2
+
+ Answer: a is 4 and b is 2.0
+
+ 6. What is the prompt displayed by ``raw_input("Say something\nType here:")``
+
+ Answer::
+
+ Say something
+ Type here:
+
+ 6. What is the prompt displayed by ``raw_input("value of a is %d\nInput b
+ value:"a)`` and ``a = 2.5``
+
+ Answer::
+
+ value of a is 2
+ Input ba value:
+
+ 7. ``a = raw_input()`` and user enters ``2.5``. What is the type of a?
+
+ a. str
+ #. int
+ #. float
+ #. char
+
+ Answer: str
+
+ 8. ``a = int(raw_input())`` and user enters ``4.5``. What happens?
+
+ a. a = 4.5
+ #. a = 4
+ #. a = 4.0
+ #. Error
+
+ Answer: Error
+
+ 9. ``a = raw_input()`` and user enters ``"this is a string"``. What does
+ ``print a`` produce?
+
+ a. 'this is a string'
+ b. 'this is a string"
+ c. "this is a string"
+ #. this is a string
+
+ Answer: "this is a string"
+
+Problems
+========
+
+ 1. Answer to universe and everything. Keep taking input from user and print it
+ back until the input is 42.
+
+ Answer::
+
+ ip = raw_input()
+ while ip != "42":
+ print ip
+
+ 2.
diff --git a/sets.rst b/sets.rst
index 4f479fc..4f7dfa1 100644
--- a/sets.rst
+++ b/sets.rst
@@ -147,3 +147,94 @@ Thankyou
Internal Reviewer 1 :
Internal Reviewer 2 :
External Reviewer :
+
+
+Questions
+=========
+
+ 1. If ``a = [1, 1, 2, 3, 3, 5, 5, 8]``. What is set(a)
+
+ a. set([1, 1, 2, 3, 3, 5, 5, 8])
+ #. set([1, 2, 3, 5, 8])
+ #. set([1, 2, 3, 3, 5, 5])
+ #. Error
+
+ Answer: set([1, 2, 3, 5, 8])
+
+ 2. ``a = set([1, 3, 5])``. How do you find the length of a?
+
+ Answer: len(a)
+
+ 3. ``a = set([1, 3, 5])``. What does a[2] produce?
+
+ a. 1
+ #. 3
+ #. 5
+ #. Error
+
+ Answer: Error
+
+ 4. ``odd = set([1, 3, 5, 7, 9])`` and ``squares = set([1, 4, 9, 16])``. What
+ is the value of ``odd | squares``?
+
+ Answer: set([1, 3, 4, 5, 7, 9, 16])
+
+ 5. ``odd = set([1, 3, 5, 7, 9])`` and ``squares = set([1, 4, 9, 16])``. What
+ is the value of ``odd - squares``?
+
+ Answer: set([3, 5, 7])
+
+ 6. ``odd = set([1, 3, 5, 7, 9])`` and ``squares = set([1, 4, 9, 16])``. What
+ is the value of ``odd ^ squares``?
+
+ Answer: set([3, 4, 5, 7, 16])
+
+ 7. ``odd = set([1, 3, 5, 7, 9])`` and ``squares = set([1, 4, 9, 16])``. What
+ does ``odd * squares`` give?
+
+ a. set([1, 12, 45, 112, 9])
+ #. set([1, 3, 4, 5, 7, 9, 16])
+ #. set([])
+ #. Error
+
+ Answer: Error
+
+ 8. ``a = set([1, 2, 3, 4])`` and ``b = set([5, 6, 7, 8])``. What is ``a + b``
+
+ a. set([1, 2, 3, 4, 5, 6, 7, 8])
+ #. set([6, 8, 10, 12])
+ #. set([5, 12, 21, 32])
+ #. Error
+
+ 9. ``a`` is a set. how do you check if if a varaible ``b`` exists in ``a``?
+
+ Answer: b in a
+
+ 10. ``a`` and ``b`` are two sets. What is ``a ^ b == (a - b) | (b - a)``?
+
+ a. True
+ #. False
+
+ Answer: False
+
+
+Problems
+========
+
+ 1. Given that mat_marks is a list of maths marks of a class. Find out the
+ no.of duplicates marks in the list.
+
+ Answer::
+
+ unique_marks = set(mat_marks)
+ no_of_duplicates = len(mat_marks) - len(unique_marks)
+
+ 2. Given that mat_marks is a list of maths marks of a class. Find how many
+ duplicates of each mark exist.
+
+ Answer::
+
+ marks_set = set(mat_marks)
+ for mark in marks_set:
+ occurences = mat_marks.count(mark)
+ print occurences - 1, "duplicates of", mark, "exist"