manipulating-lists/questions.rst
changeset 324 4054b1a6392d
parent 312 8cb703eee88d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/manipulating-lists/questions.rst	Wed Oct 13 17:32:59 2010 +0530
@@ -0,0 +1,72 @@
+Objective Questions
+-------------------
+
+.. A mininum of 8 questions here (along with answers)
+
+1. Given the list primes, ``primes = [2, 3, 5, 7, 11, 13, 17, 19, 23,
+   29]``, How do you obtain the last 4 primes?
+
+   Answer: primes[-4:]
+
+#. Given the list primes, ``primes = [2, 3, 5, 7, 11, 13, 17, 19, 23,
+   29]``, What is the output of ``primes[::5]``?
+
+   Answer: ``[2, 13]``
+   
+#. Given a list, p, of unknown length, obtain the first 3 (or all, if
+   there are fewer) characters of it. 
+
+   Answer: p[:3]
+
+#. The method ``reverse`` reverses a list in-place. True or False?
+
+   Answer: True
+   
+#. ``reversed`` function reverses a list in-place. True or False?
+
+   Answer: False
+
+#. Given the list ``p = [1, 2, 3]``. p[4] produces an IndexError. True
+   or False?
+
+   Answer: True
+
+#. Given the list ``p = [1, 2, 3]``. p[:4] produces an IndexError. True
+   or False?
+
+   Answer: False
+
+#. Given the list primes, ``primes = [2, 3, 5, 7, 11]``, What is the
+   output of ``primes[::-1]``?
+
+   Answer: [11, 7, 5, 3, 2]
+
+#. Given the list primes, ``primes = [2, 3, 5, 7, 11]``, What is the
+   output of ``primes[::-3]``?
+
+   Answer: [11, 3]
+
+
+Larger Questions
+----------------
+
+.. A minimum of 2 questions here (along with answers)
+
+#. Given a list p. Append it's reverse to itself. 
+
+   Answer::
+
+      p = p + reversed(p)
+
+
+#. Marks is a list containing the roll numbers of students followed by
+   marks. [This is not a recommended way to hold the marks details,
+   but the teacher knows only so much Python!] Now she wants to get
+   the average of the marks. Help her do it. 
+
+   Answer::
+
+     marks = [1, 9, 2, 8, 3, 3, 4, 10, 5, 2]
+     average = sum(marks[1::2])/len(marks[1::2])
+
+