getting-started-with-for/questions.rst
changeset 261 c7f0069d698a
equal deleted inserted replaced
260:25b4e962b55e 261:c7f0069d698a
       
     1 Objective Questions
       
     2 -------------------
       
     3 
       
     4 .. A mininum of 8 questions here (along with answers)
       
     5 
       
     6 1. In Python a block is represented by
       
     7 
       
     8    a. Curly braces
       
     9    #. Begin and End keywords
       
    10    #. Indentation
       
    11    #. Curly braces + Indentation
       
    12    #. All of the above
       
    13 
       
    14 Answer: Indentation
       
    15 
       
    16 2. Indentation is not mandatory in Python
       
    17 
       
    18    a. True
       
    19    #. False
       
    20 
       
    21 Answer: False
       
    22 
       
    23 3. A ``for`` loop in Python,
       
    24 
       
    25    a. is a simple iterator
       
    26    #. is a condition based loop
       
    27    #. can iterate only over integer list of elements
       
    28    #. All of the above
       
    29 
       
    30 Answer: is a simple iterator
       
    31 
       
    32 4. ``range()`` function can generate negative numbers
       
    33 
       
    34    a. True
       
    35    #. False
       
    36 
       
    37 Answer: True
       
    38 
       
    39 5. ``range(a,b)`` function returns,
       
    40 
       
    41    a. A tuple of elements from a to b including a and b
       
    42    #. A tuple of elements from a to b excluding b
       
    43    #. A list of elements from a to b including a and b
       
    44    #. A list of elements from a to b excluding b
       
    45 
       
    46 Answer: A list of elements from a to b excluding b
       
    47 
       
    48 6. ``linspace(1,100,2)`` and ``range(1,100,2)`` produces the same output,
       
    49 
       
    50    a. True
       
    51    #. False
       
    52 
       
    53 Answer: False
       
    54 
       
    55 7. What is the output of the below code snippet?
       
    56    ::
       
    57 
       
    58      y = 1
       
    59      for x in range(21):
       
    60          y*=x
       
    61      print y
       
    62 
       
    63    a. Product of natural numbers up to 20(including)
       
    64    #. Product of natural numbers up to 21(including)
       
    65    #. Zero
       
    66    #. Error
       
    67 
       
    68 Answer: Zero
       
    69 
       
    70 8. What is the output of the below code snippet?
       
    71    ::
       
    72 
       
    73     y = 1
       
    74     for x in range(1,21):
       
    75         y*=x
       
    76     print y
       
    77 
       
    78    a. Product of natural numbers up to 20(including)
       
    79    #. Product of natural numbers up to 21(including)
       
    80    #. Zero
       
    81    #. Error
       
    82 
       
    83 Answer: Product of natural numbers up to 20(including)
       
    84 
       
    85 9. What is the output of the below code snippet?
       
    86    ::
       
    87 
       
    88     y = 1
       
    89     for x in range(1,21)
       
    90         y*=x
       
    91     print y
       
    92 
       
    93    a. Product of natural numbers up to 20(including)
       
    94    #. Product of natural numbers up to 21(including)
       
    95    #. Zero
       
    96    #. Error
       
    97 
       
    98 Answer: Error
       
    99 
       
   100 Larger Questions
       
   101 ----------------
       
   102 
       
   103 .. A minimum of 2 questions here (along with answers)
       
   104 
       
   105 1. Write a python script to calculate the sum of the first 1000
       
   106     natural numbers?
       
   107 
       
   108 2. Write a python script to find out prime numbers up to 500.
       
   109     [`hint`: a number ``A`` which is divisible by only ``1`` and ``A``
       
   110     is a prime number.]
       
   111 
       
   112 3. Write a python script to find out the difference between the
       
   113     square of sum of first 100 natural numbers and sum of squares of
       
   114     first 100 natural numbers.
       
   115