diff -r 88a01948450d -r d33698326409 getting_started_with_for/questions.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/getting_started_with_for/questions.rst Wed Dec 01 16:51:35 2010 +0530 @@ -0,0 +1,115 @@ +Objective Questions +------------------- + +.. A mininum of 8 questions here (along with answers) + +1. In Python a block is represented by + + a. Curly braces + #. Begin and End keywords + #. Indentation + #. Curly braces + Indentation + #. All of the above + +Answer: Indentation + +2. Indentation is not mandatory in Python + + a. True + #. False + +Answer: False + +3. A ``for`` loop in Python, + + a. is a simple iterator + #. is a condition based loop + #. can iterate only over integer list of elements + #. All of the above + +Answer: is a simple iterator + +4. ``range()`` function can generate negative numbers + + a. True + #. False + +Answer: True + +5. ``range(a,b)`` function returns, + + a. A tuple of elements from a to b including a and b + #. A tuple of elements from a to b excluding b + #. A list of elements from a to b including a and b + #. A list of elements from a to b excluding b + +Answer: A list of elements from a to b excluding b + +6. ``linspace(1,100,2)`` and ``range(1,100,2)`` produces the same output, + + a. True + #. False + +Answer: False + +7. What is the output of the below code snippet? + :: + + y = 1 + for x in range(21): + y*=x + print y + + a. Product of natural numbers up to 20(including) + #. Product of natural numbers up to 21(including) + #. Zero + #. Error + +Answer: Zero + +8. What is the output of the below code snippet? + :: + + y = 1 + for x in range(1,21): + y*=x + print y + + a. Product of natural numbers up to 20(including) + #. Product of natural numbers up to 21(including) + #. Zero + #. Error + +Answer: Product of natural numbers up to 20(including) + +9. What is the output of the below code snippet? + :: + + y = 1 + for x in range(1,21) + y*=x + print y + + a. Product of natural numbers up to 20(including) + #. Product of natural numbers up to 21(including) + #. Zero + #. Error + +Answer: Error + +Larger Questions +---------------- + +.. A minimum of 2 questions here (along with answers) + +1. Write a python script to calculate the sum of the first 1000 + natural numbers? + +2. Write a python script to find out prime numbers up to 500. + [`hint`: a number ``A`` which is divisible by only ``1`` and ``A`` + is a prime number.] + +3. Write a python script to find out the difference between the + square of sum of first 100 natural numbers and sum of squares of + first 100 natural numbers. +