getting-started-files/questions.rst
changeset 245 3ed6ef2ea91f
parent 217 b595f90016c5
child 292 de96931fac21
--- a/getting-started-files/questions.rst	Thu Oct 07 15:11:00 2010 +0530
+++ b/getting-started-files/questions.rst	Thu Oct 07 15:11:38 2010 +0530
@@ -1,17 +1,134 @@
-Objective
----------
+Objective Questions
+-------------------
 
 .. A mininum of 8 questions here. 
 
-1. Question 1
-2. Question 2
-3. Question 3
+1. What function is used to open a file?
+
+   Answer: ``open``
+
+#. The ``open`` function returns a 
+
+   a. string
+   #. list
+   #. file object
+   #. function
+
+   Answer: file object
+
+#. ``open`` function opens a file by default in write mode. T or F?
+   
+   Answer: False
+
+#. The ``read`` method reads a file and returns the contents
+
+   a. string
+   #. list
+   #. file object
+   #. None of the above
+
+   Answer: string
+
+#. Given a file with ``hello.txt``, which looks like 
+   ::
+     
+     Hello, World!
+
+   What is the value of content, at the end of this code block::
+
+     f = open('hello.txt')
+     content = f.read()
+     content = f.read()
+     f.close()
+
+   Answer: It is a null string. 
+
+#. The following code block prints each line of ``hello.txt``::
+
+     f = open('hello.txt')
+     for line in f.read():
+         print line
+
+   True or False?
+
+   Answer: False
+
+#. Given a file with ``hello.txt``, which looks like 
+   ::
+     
+     Hello, World!
+
+   What is the output of ::
+
+     f = open('hello.txt')
+
+     for line in f:
+         print line
+
+     for line in f:
+         print line
+
+     f.close()
+
+   Answer: Hello, World! is printed once.
+
+           .. The actual answer should talk about blank lines, but I'm
+           .. not sure if we should get into such detail. 
+
+           .. Should this be made a multiple-choice?
+
+   
+#. Given a file with ``hello.txt``, which looks like 
+   ::
+     
+     Hello, World!
+
+   What is the output of ::
+
+     f = open('hello.txt')
+
+     for line in f:
+         print line
+
+     f.close()
+
+     for line in f:
+         print line
+
+     f.close()
+
+   Answer: Hello, World! is printed twice.
+
+#. Given a file with ``hello.txt``, which looks like 
+   ::
+     
+     Hello, World!
+
+   What is the output of ::
+
+     f = open('hello')
+
+     for line in f:
+         print line
+
+     f.close()
+
+     for line in f:
+         print line
+
+     f.close()
+
+   Answer: IOError - No such file or directory: 'hello'
 
 
-Programming
------------
+Larger Questions
+----------------
 
 .. A minimum of 2 questions here. 
 
-1. Programming Assignment 1
-2. Programming Assignment 2
+1. f.read(size)
+
+#. Print every alternate line of a file, starting at the first line. 
+
+#. Print the file in reverse. Starting from the last line to the
+   first.