basic-data-type/questions.rst
author bhanu
Mon, 15 Nov 2010 15:14:12 +0530
changeset 507 34b8f90a88cb
parent 406 a534e9e79599
permissions -rw-r--r--
Language check done for `sets`
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
320
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
     1
Objective Questions
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
     2
-------------------
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
     3
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
     4
.. A mininum of 8 questions here (along with answers)
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
     5
337
c65d0d9fc0c8 Reviewed Basic datatypes LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 320
diff changeset
     6
.. #[Puneeth: ``Answer: Any size.``. Demarcate the answer from the
c65d0d9fc0c8 Reviewed Basic datatypes LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 320
diff changeset
     7
.. question.]
c65d0d9fc0c8 Reviewed Basic datatypes LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 320
diff changeset
     8
320
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
     9
1. How large can an integer in Python be?
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    10
406
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    11
   Answer: Any Size.
320
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    12
   
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    13
  
406
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    14
#. How do you define a complex number in Python?
320
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    15
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    16
   Using the following notation.
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    17
   
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    18
   [Real part] + [Imaginary part] j
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    19
   example ::
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    20
   
406
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    21
   Answer: c= 3.2 + 4.6j
320
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    22
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    23
406
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    24
#. Look at the following piece of code ::
320
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    25
   
337
c65d0d9fc0c8 Reviewed Basic datatypes LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 320
diff changeset
    26
     In []: f or t 
c65d0d9fc0c8 Reviewed Basic datatypes LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 320
diff changeset
    27
     Out[]:True
320
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    28
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    29
   What can you comment about the data type of f and t ? 
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    30
406
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    31
#. One major diffence between tuples and lists?
320
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    32
406
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    33
   Answer: Tuples are immutable while lists are not.
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    34
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    35
320
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    36
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    37
406
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    38
#. Put the following string in a variable quotation.
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    39
   "God doesn't play dice" -Albert Einstein
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    40
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    41
   quotation='''"God doesn't play dice" -Albert Einstein'''
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    42
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    43
#. Given a tuple ::
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    44
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    45
     tup=(7,4,2,1,3,6,5,8)
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    46
     tup[-2]
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    47
  
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    48
   5
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    49
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    50
.. #[Puneeth: ``Answer: Any size.``. Demarcate the answer from the
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    51
.. question.]
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    52
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    53
#. What is the syntax for checking containership in Python?::
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    54
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    55
   element in sequence 
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    56
   'l' in "Hello"
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    57
    True
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    58
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    59
#. Split this string on whitespaces? ::
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    60
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    61
   string="Split this string on whitespaces?"
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    62
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    63
   string.split()
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    64
   
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    65
#. What is the answer of 5/2 and 5.0/2 . If yes , why.
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    66
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    67
    Yes, There is a difference. 
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    68
    Because one is integer division and other is float division. 
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    69
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    70
Larger Questions
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    71
----------------
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    72
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    73
.. A minimum of 2 questions here (along with answers)
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    74
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    75
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    76
1. Look at the following sequence ::
320
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    77
337
c65d0d9fc0c8 Reviewed Basic datatypes LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 320
diff changeset
    78
     In []:t=true
c65d0d9fc0c8 Reviewed Basic datatypes LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 320
diff changeset
    79
     NameError: name 'true' is not defined
320
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    80
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    81
   What might be the reason for error here?
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    82
337
c65d0d9fc0c8 Reviewed Basic datatypes LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 320
diff changeset
    83
   In this scenario , it seems the programmer wanted to create a
c65d0d9fc0c8 Reviewed Basic datatypes LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 320
diff changeset
    84
   variable t with the boolean value True with a capital T. Since no
c65d0d9fc0c8 Reviewed Basic datatypes LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 320
diff changeset
    85
   variable by the name true(small t) is known to the interpreter it
c65d0d9fc0c8 Reviewed Basic datatypes LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 320
diff changeset
    86
   gives a NameError.
320
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    87
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    88
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    89
406
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    90
#. Convert the string "I,learnt,python,through,spoken,tutorial"
a534e9e79599 Completed basic data type based on review and improved on slides
Amit Sethi
parents: 337
diff changeset
    91
   to "I,learnt through spoken tutorial"
320
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    92
337
c65d0d9fc0c8 Reviewed Basic datatypes LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 320
diff changeset
    93
.. #[Puneeth: comparison has not been taught, has it? does this depend
c65d0d9fc0c8 Reviewed Basic datatypes LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 320
diff changeset
    94
.. on any other LO?]