Professional Documents
Culture Documents
Final Exam
Problem #1
1. The number of collections of k objects without repetition from a set of n objects is given by
the formula,
Notice that ‘n choose k’ is always an integer, even though it results from a division. Which
means that the function should always return an integer, not a float.
To test the function show that for a poker hand of 5 cards choosen without repetition from a
deck of 52 cards there are 2 598 960 combinations.
2. Tartaglia’s triangle (after Nicolò Fontana Tartaglia who published it in 1556) is a triangular
array of “n choose k”, illustrated by the figure below:
There is more than one way to generate the coefficients of the Tartaglia’s triangle, but perhaps
the simplest in Python is to create a nested list in which n is the row (starting at 0), and k is
column (also starting at 0). We see that in the array above, the fifth row (n = 4), has 5 elements,
k from 0 to 4.
Write a Python function to make a nested list that contains the coefficients of Tartaglia’s
triangle.
[[1],
[1, 1],
AYPC_4 2 of 5
[1, 2, 1],
[1, 3, 3, 1],
[1, 4, 6, 4, 1],
[1, 5, 10, 10, 5, 1],
[1, 6, 15, 20, 15, 6, 1]]
3. From the coefficients in a Tartaglia triangle, create a dictionary in which the key is the row
number, and the value is a list of the coefficients corresponding to that row:
{row: [coefficients of row]}
4. For a given set of n objects the sum of all possible collections of k objects taken is equal to
the number of permutations. For example, if from a set of 3 objects we choose 0, 1, 2 and
3, the sum of these collections equals 2**3, the number of possible permutations.
Using the dictionary built in (3) above, show that for any row n of a Tartaglia triangle the
sum of the coefficients is equal to 2**n.
Test your code with a triangle of 15 rows. The results should be the same as the table below:
Problem #2
AMPLITUDE MODULATION
To transmit information over a distance without a cable connection, what we call “wireless
transmission”, engineers have developed a techique called modulation. There are various types
of modulation but the simplest of all is amplitude modulation (AM). An electromagnetic wave
which has the information (or sound) is superimposed on another electromagnetic wave of
fixed frequency called the carrier signal. The “sound” wave changes, or modulates, the
amplitude of the carrier, while its frequency remains unchanged.
AYPC_4 3 of 5
The carrier is a higher-frequency wave (around 1 MHz for broadcast radio), like this simple
sinusoidal wave:
The message signal, which contains the sound, could be something like in the figure below.
The amplitude modulation is done by multiplying the carrier wave with the message, let’s call it
m(t). If the carrier wave is Acos(2πfct), then the AM-modulated carrier is given by
(1 + m(t))Acos(2πfct). A 1 is added to the message to raise it to the range [0, 2] so that the
carrier just vanishes at the smallest message values. The result is shown in the next figure.
The original message is the envelope of the modulated carrier (in red). Notice that it is not
changed in any way. The carrier wave, however, has its amplitude changed, but not its
frequency. The radio receiver is tuned to the frequency of the carrier, fc, detects it and extracts
the message.
A COMPUTER MODEL
We can model amplitude modulation by plotting three graphs on the same plane. When
studying and testing analog modulation, it is convenient to use a sinusoid as the message
signal. The independent variable is time, t, which in this exercise will be represented by x.
Using the guide provided by the Python program GuideProblem2.py (download it), you are to
draw three graphs, properly identified and labeled. In addition to the problem guide, you
also need to download to the working directory the module PlotFunctions.py that contain the
functions that you will use to plot the graphs.
1 + modulation_index*sin(2πx)
AYPC_4 4 of 5
– (1 + modulation_index*sin(2πx))
This is simply the negative value of the expression in (1).
(3) The carrier wave for the exercise is cos(16πx). Plot the AM-modulated carrier, which
is given by the expression:
(1+ modulation_index*sin(2πx))*cos(16πx)
The complete plot must include, the axes with labels, marks on the axes with labels, the 3
graphs in different colors (1 and 2 should have the same color), a legend on the upper left-hand
side, a label indicating the value of the modulation_index, and a title for the whole plot. Follow
the instructions and comments in the guide, GuideProblem2.py.
Problem #3
With the same data file used in Problem#2 Week#14, students.txt, calculate for each student
the Grade Point Average (GPA), and store it in a dictionary together with the list of courses and
grades.
The GPA for a student is a weighted average of the grades obtained in a particular period. For
example, student Andrés Pilo. has obtained these grades in the first semester:
EXOE 3, 3.1
PREM 4, 4.2
AYPC_4 5 of 5
AGEO 4, 2.8
IINE 2, 4.5
ALI 3, 3.5
The grade points (or credit points) earned was: (3x3.1 + 4x4.2 + 4x2.8 + 2x4.5 + 3x3.5) = 56.8
2. For each student calculate the GPA with the procedure described in the previous
parragraph. Round the GPA to two digits after the decimal point.
3. Create a dictionary in which the key is the student’s full name (apellidos + nombres), and
the values are the GPA and a list of courses. The list has the course identifier, the number
of credits and the grade obtained. An example of an entry in the dictionary follows:
This problem is somewhat similar to Problem#2 of Week 14. A suggestion is to use the function
developed in Problem#2 of Week 14 student_dict(file_name), and modify it to calculate the
GPA and the new dictionary.