basic-data-type/questions.rst
author Puneeth Chaganti <punchagan@fossee.in>
Tue, 19 Oct 2010 14:26:02 +0530
changeset 337 c65d0d9fc0c8
parent 320 223044cf254f
child 406 a534e9e79599
permissions -rw-r--r--
Reviewed Basic datatypes LO.
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
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    11
   Any Size.
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
  
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    14
2. How do you define a complex number in Python?
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
   
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    21
   c= 3.2 + 4.6j
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
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    24
3. Look at the following piece of code ::
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
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    31
4. One major diffence between tuples and lists?
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    32
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    33
   Tuples are immutable while lists are not.
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    34
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    35
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    36
5. Look at the following sequence ::
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    37
337
c65d0d9fc0c8 Reviewed Basic datatypes LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 320
diff changeset
    38
     In []:t=true
c65d0d9fc0c8 Reviewed Basic datatypes LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 320
diff changeset
    39
     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
    40
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    41
   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
    42
337
c65d0d9fc0c8 Reviewed Basic datatypes LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 320
diff changeset
    43
   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
    44
   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
    45
   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
    46
   gives a NameError.
320
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    47
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    48
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    49
6. Put the following string in a variable quotation.
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    50
   "God doesn't play dice" -Albert Einstein
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    51
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    52
   quotation='''"God doesn't play dice" -Albert Einstein'''
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    53
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    54
7. Given a tuple ::
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    55
337
c65d0d9fc0c8 Reviewed Basic datatypes LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 320
diff changeset
    56
     tup=(7,4,2,1,3,6,5,8)
c65d0d9fc0c8 Reviewed Basic datatypes LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 320
diff changeset
    57
     tup[-2]
320
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    58
  
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    59
   5
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    60
337
c65d0d9fc0c8 Reviewed Basic datatypes LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 320
diff changeset
    61
.. #[Puneeth: ``Answer: Any size.``. Demarcate the answer from the
c65d0d9fc0c8 Reviewed Basic datatypes LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 320
diff changeset
    62
.. question.]
c65d0d9fc0c8 Reviewed Basic datatypes LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 320
diff changeset
    63
320
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    64
8. What is the syntax for checking containership in Python?::
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    65
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    66
   element in sequence 
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    67
   'l' in "Hello"
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    68
    True
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    69
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    70
9. Split this string on whitespaces? ::
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    71
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    72
   string="Split this string on whitespaces?"
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    73
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    74
   string.split()
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    75
   
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    76
10. What is the answer of 5/2 and 5.0/2 . If yes , why.
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    77
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    78
    Yes, There is a difference. 
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    79
    Because one is integer division and other is float division. 
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
Larger Questions
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    82
----------------
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    83
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    84
.. A minimum of 2 questions here (along with answers)
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    85
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    86
1. Given two lists for example,
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    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.
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    88
337
c65d0d9fc0c8 Reviewed Basic datatypes LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 320
diff changeset
    89
.. #[Puneeth: dependency LOs?]
320
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    90
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    91
#. Write a program to check if a string is palindrome?
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?]