Merged heads.
authorPuneeth Chaganti <punchagan@fossee.in>
Thu, 07 Oct 2010 12:28:24 +0530
changeset 243 62cb96a8f6b9
parent 242 a33e942379d7 (current diff)
parent 231 e78c284d644b (diff)
child 244 b67d5e07cab5
Merged heads.
--- a/input_output.rst	Thu Oct 07 12:28:12 2010 +0530
+++ b/input_output.rst	Thu Oct 07 12:28:24 2010 +0530
@@ -180,3 +180,109 @@
    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. 
--- a/sets.rst	Thu Oct 07 12:28:12 2010 +0530
+++ b/sets.rst	Thu Oct 07 12:28:24 2010 +0530
@@ -147,3 +147,94 @@
    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"