basic-data-type/questions.rst
author amit
Wed, 13 Oct 2010 17:10:38 +0530
changeset 320 223044cf254f
child 337 c65d0d9fc0c8
permissions -rw-r--r--
Adding new format st-scripts with questions etc for basic-data-type and getting started with lists
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
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
     6
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
     7
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
     8
   Any Size.
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
     9
   
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
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
    12
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    13
   Using the following notation.
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    14
   
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    15
   [Real part] + [Imaginary part] j
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    16
   example ::
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
   c= 3.2 + 4.6j
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    19
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
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    22
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
    23
   
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    24
   In []: f or t 
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    25
   Out[]:True
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    26
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    27
   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
    28
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    29
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
    30
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    31
   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
    32
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    33
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    34
5. Look at the following sequence ::
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
   In []:t=true
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    37
   NameError: name 'true' is not defined
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    38
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    39
   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
    40
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    41
   In this scenario , it seems the programmer wanted to create a variable t with the boolean value True with a capital T. Since no variable by the name true(small t) is known to the interpreter it gives a NameError. 
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    42
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    43
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    44
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
    45
   "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
    46
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    47
   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
    48
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    49
7. Given a tuple ::
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    50
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    51
   tup=(7,4,2,1,3,6,5,8)
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    52
   tup[-2]
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
   5
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    55
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    56
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
    57
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    58
   element in sequence 
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    59
   'l' in "Hello"
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    60
    True
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    61
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    62
9. Split this string on whitespaces? ::
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    63
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    64
   string="Split this string on whitespaces?"
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
   string.split()
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    67
   
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    68
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
    69
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    70
    Yes, There is a difference. 
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    71
    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
    72
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    73
Larger Questions
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    74
----------------
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
.. 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
    77
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    78
1. Given two lists for example,
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    79
   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
    80
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    81
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
diff changeset
    82
#. 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
    83