Mid-term exams¶
This is a closed book exam.
Answer all questions using a Jupyter notebook with the Python 3 kernel.
- For
Unix shell commands, please use the%%bashcell magic when running Unix commands. - For Python, only use built-ins and standard library modules. In
particular, you are not allowed to use
numpyortoolzfor this exam.
Each question is worth 25 points.
Start of exam¶
1. Using bash for loops, write the commands to create a set of
nested directories as shown, where a is the top level directory
created.
a
b1
c1
c2
b2
c1
c2
b3
c1
c2
In [71]:
2. A palindrome is a phrase that reads the same forwards and backwards, for example: “Madam, I’m Adam!”. Ignore spaces, case and punctuation when finding palindromes. Write code to find the palindromes among the 12 phrases below, returning the phrases that are palindromes in a list.
Daedalus: nine. Peninsula: dead.
Dammit, I'm mad!
Deliver me from evil.
Dennis and Edna sinned.
Devil never even lived.
Deviled eggs sure taste good.
Did Hannah see bees? Hannah did.
Do geese see God?
Do mice see God?
Dogma: I am God
Dogma: DNA makdes RNA makes protein.
Dubya won? No way, bud.
In [94]:
3. The logistic map is defined by the following simple function
For \(x_0 = 0.1\) and \(r = 4.0\), store the first 10 values of the iterated logistic map \(x_{i+1} = rx_i(1-x_i)\) in a list. The first value in the list should be \(x_0\).
In [8]:
4. Write a function to find the greatest common divisor (GCD) of 2 numbers using Euclid’s algorithm.:
Find the GCD of 5797 and 190978.
Now write a function to find the GCD given a collection of numbers.
Find the GCD of (24, 48, 60, 120, 8).
In [39]: