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