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