loops/questions.rst
author amit
Wed, 27 Oct 2010 15:13:17 +0530
changeset 362 a77a27916f81
parent 293 ca701f1ef7fb
child 366 894591150f7b
permissions -rw-r--r--
Added Objectives and other metadata
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
254
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
     1
Objective Questions
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
     2
-------------------
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     3
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     4
.. A mininum of 8 questions here. 
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     5
254
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
     6
1. Braces are used to indicate blocks in Python. True or False?
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
     7
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
     8
   Answer: False
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
     9
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    10
#. ``for`` can iterate over 
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    11
   
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    12
   a. list of numbers
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    13
   #. list of strings
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    14
   #. strings
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    15
   #. tuples
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    16
   #. all of the above
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    17
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    18
.. I was not sure of how to frame this question. Can someone fix it?
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    19
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    20
   Answer: all of the above
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    21
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    22
#. ``x = range(20)``. What is x?
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    23
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    24
   Answer: A list of numbers from 0 to 19. 
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    25
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    26
#. ``x = range(5, 20)``. What is x?
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    27
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    28
   Answer: A list of numbers from 5 to 19. 
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    29
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    30
#. ``x = range(0, 20, 5)``. What is x?
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    31
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    32
   a. [5, 10, 15, 20]
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    33
   #. [0, 5, 10, 15, 20]
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    34
   #. [0, 5, 10, 15]
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    35
   #. Empty list
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    36
   #. None of the Above
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    37
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    38
   Answer: [0, 5, 10, 15]
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    39
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    40
#. ``x = range(20, 5)``. What is x?
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    41
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    42
   a. [5, 10, 15, 20]
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    43
   #. [0, 5, 10, 15, 20]
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    44
   #. [0, 5, 10, 15]
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    45
   #. Empty list
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    46
   #. None of the Above
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    47
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    48
   Answer: Empty list
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    49
254
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    50
#. ``x = range(20, 5, -1)``. What is x?
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    51
254
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    52
   Answer: A list of numbers from 20 to 6.
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    53
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    54
#. What is the output of the following code block?
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    55
   ::
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    56
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    57
     for i in range(1, 4):
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    58
         for j in range(1, 4):
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    59
             print i * j
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    60
             break
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    61
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    62
   Answer: 1 to 3 is printed
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    63
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    64
#. What is the output of the following code block?
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    65
   ::
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    66
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    67
     for i in range(1, 4):
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    68
         for j in range(1, 4):
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    69
             pass
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    70
             print i * j
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    71
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    72
   Answer::
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    73
     
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    74
     3
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    75
     6
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    76
     9
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    77
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    78
#. What is the output of the following code block?
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    79
   ::
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    80
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    81
     for i in range(1, 4):
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    82
         for j in range(1, 4):
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    83
             continue
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    84
             print i * j
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    85
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    86
   Answer: Nothing is printed
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    87
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    88
Larger Questions
c43677920502 added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    89
----------------
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    90
293
ca701f1ef7fb reviewed questions
Nishanth <nishanth@fossee.in>
parents: 254
diff changeset
    91
1. A number is called Armstrong number if the sum of cubes of its digits is
ca701f1ef7fb reviewed questions
Nishanth <nishanth@fossee.in>
parents: 254
diff changeset
    92
   equal to the number itself. Find all the three digit Armstrong numbers.
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    93