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.

Objective Questions
-------------------

.. A mininum of 8 questions here (along with answers)

.. #[Puneeth: ``Answer: Any size.``. Demarcate the answer from the
.. question.]

1. How large can an integer in Python be?

   Any Size.
   
  
2. How do you define a complex number in Python?

   Using the following notation.
   
   [Real part] + [Imaginary part] j
   example ::
   
   c= 3.2 + 4.6j


3. Look at the following piece of code ::
   
     In []: f or t 
     Out[]:True

   What can you comment about the data type of f and t ? 

4. One major diffence between tuples and lists?

   Tuples are immutable while lists are not.


5. Look at the following sequence ::

     In []:t=true
     NameError: name 'true' is not defined

   What might be the reason for error here?

   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.


6. Put the following string in a variable quotation.
   "God doesn't play dice" -Albert Einstein

   quotation='''"God doesn't play dice" -Albert Einstein'''

7. Given a tuple ::

     tup=(7,4,2,1,3,6,5,8)
     tup[-2]
  
   5

.. #[Puneeth: ``Answer: Any size.``. Demarcate the answer from the
.. question.]

8. What is the syntax for checking containership in Python?::

   element in sequence 
   'l' in "Hello"
    True

9. Split this string on whitespaces? ::

   string="Split this string on whitespaces?"

   string.split()
   
10. What is the answer of 5/2 and 5.0/2 . If yes , why.

    Yes, There is a difference. 
    Because one is integer division and other is float division. 

Larger Questions
----------------

.. A minimum of 2 questions here (along with answers)

1. Given two lists for example,
   list1=[1,2,3,4] and list2=[1,2,3,4,5,6,7] write a program to remove one list from the other.

.. #[Puneeth: dependency LOs?]

#. Write a program to check if a string is palindrome?

.. #[Puneeth: comparison has not been taught, has it? does this depend
.. on any other LO?]