using_sage_to_teach/questions.rst
author Nishanth <nishanth@fossee.in>
Fri, 08 Oct 2010 23:55:07 +0530
changeset 256 a3aa223c1662
child 262 0038edaf660c
permissions -rw-r--r--
added script to using_sage_to_teach
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
256
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
     1
Objective Questions
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
     2
-------------------
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
     3
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
     4
 1. If ``a = [1, 1, 2, 3, 3, 5, 5, 8]``. What is set(a)
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
     5
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
     6
   a. set([1, 1, 2, 3, 3, 5, 5, 8])
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
     7
   #. set([1, 2, 3, 5, 8])
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
     8
   #. set([1, 2, 3, 3, 5, 5])
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
     9
   #. Error
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    10
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    11
   Answer: set([1, 2, 3, 5, 8])
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    12
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    13
 2. ``a = set([1, 3, 5])``. How do you find the length of a?
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    14
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    15
   Answer: len(a)
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    16
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    17
 3. ``a = set([1, 3, 5])``. What does a[2] produce?
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    18
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    19
   a. 1
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    20
   #. 3
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    21
   #. 5
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    22
   #. Error
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    23
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    24
   Answer: Error
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    25
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    26
 4. ``odd = set([1, 3, 5, 7, 9])`` and ``squares = set([1, 4, 9, 16])``. What
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    27
    is the value of ``odd | squares``?
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    28
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    29
   Answer: set([1, 3, 4, 5, 7, 9, 16])
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    30
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    31
 5. ``odd = set([1, 3, 5, 7, 9])`` and ``squares = set([1, 4, 9, 16])``. What
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    32
    is the value of ``odd - squares``?
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    33
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    34
   Answer: set([3, 5, 7])
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    35
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    36
 6. ``odd = set([1, 3, 5, 7, 9])`` and ``squares = set([1, 4, 9, 16])``. What
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    37
    is the value of ``odd ^ squares``?
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    38
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    39
   Answer: set([3, 4, 5, 7, 16])
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    40
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    41
 7. ``odd = set([1, 3, 5, 7, 9])`` and ``squares = set([1, 4, 9, 16])``. What
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    42
    does ``odd * squares`` give?
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    43
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    44
   a. set([1, 12, 45, 112, 9])
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    45
   #. set([1, 3, 4, 5, 7, 9, 16])
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    46
   #. set([])
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    47
   #. Error
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    48
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    49
   Answer: Error
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    50
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    51
 8. ``a = set([1, 2, 3, 4])`` and ``b = set([5, 6, 7, 8])``. What is ``a + b``
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    52
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    53
   a. set([1, 2, 3, 4, 5, 6, 7, 8])
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    54
   #. set([6, 8, 10, 12])
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    55
   #. set([5, 12, 21, 32])
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    56
   #. Error
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    57
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    58
 9. ``a`` is a set. how do you check if if a varaible ``b`` exists in ``a``?
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    59
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    60
   Answer: b in a
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    61
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    62
 10. ``a`` and ``b`` are two sets. What is ``a ^ b == (a - b) | (b - a)``?
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    63
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    64
   a. True
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    65
   #. False
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    66
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    67
   Answer: False
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    68
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    69
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    70
Larger Questions
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    71
----------------
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    72
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    73
 1. Given that mat_marks is a list of maths marks of a class. Find out the
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    74
    no.of duplicates marks in the list.
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    75
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    76
   Answer::
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    77
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    78
     unique_marks = set(mat_marks)
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    79
     no_of_duplicates = len(mat_marks) - len(unique_marks)
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    80
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    81
 2. Given that mat_marks is a list of maths marks of a class. Find how many
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    82
    duplicates of each mark exist.
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    83
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    84
   Answer::
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    85
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    86
     marks_set = set(mat_marks)
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    87
     for mark in marks_set:
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    88
         occurences = mat_marks.count(mark)
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    89
         print occurences - 1, "duplicates of", mark, "exist"
a3aa223c1662 added script to using_sage_to_teach
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    90