- \n",
"
- To help you learn some Python essentials and programming skills to enjoy the remainder of this course.\n", "

- \n",
"
- Complete the notebook below, as follows. Click on a question, then from the menu select Insert -> Insert Cell Below. From the dropdown box (next to the \"stop\" symbol) choose whether you wish to insert 'Code' or 'Markdown'. Save regularly! \n", " \n", "
- Press Shift-Enter to execute the code in a cell.\n", "\n", "
- Submit the .ipynb file via http://somas-uploads.shef.ac.uk/mas212 by 23.59pm on Sun 8th Oct 2017.
*If you are off-campus, you will need to use a VPN to submit.*\n", "\n", " - Your lecturer will mark each question as either 2 (good), 1 (needs revision), 0 (not attempted/wrong).\n", "\n", "
- This is an open-book test, which means you may consult books, notes and internet resources.
**Do not discuss or share your test with anyone**. Copy-and-pasting is**not permitted**.*Please give answers in your own words.*\n", "

- \n",
"
- Lecture materials and links on course web page: http://sam-dolan.staff.shef.ac.uk/mas212/\n", "

\n", "

`int`

, `float`

and `complex`

. `int`

is an integer, a whole number, that is, any finite member of the set $\\mathbb{Z}$. `float`

is a floating-point number: a representation of a member of the reals $\\mathbb{R}$ with a finite precision for its mantissa and exponent. `complex`

is a representation of a complex number in $\\mathbb{C}$: it can be thought of as a pair of `float`

s, representing its real and imaginary parts."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"`list`

and `ndarray`

types).- \n",
"
- Arrays are homogeneous, whereas lists are heterogeneous. In other words, all elements of an array must have the same data type, whereas elements of lists may have different data types.\n", "
- Arrays are typically fixed in size, whereas lists can be lengthened or shortened.\n", "
- Arrays are typically contiguous chunks of memory, whereas lists are not.\n", "
- Arrays may be operated on with universal functions (ufuncs, see below), which operate on a whole array in an efficient manner. This enables vectorizaton. Universal functions are not available for lists.\n", "
- Arrays can be multi-dimensional, whereas lists are one-dimensional (though lists-of-lists can be used to mimic multi-dimensional structures).\n", "

`int, list, tuple, dict, set, string, float`

)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Mutable means \"can be changed\". The container types `list`

, `dict`

and `set`

are mutable, whereas int, tuple, string and float are not."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"`numpy`

module)`numpy`

includes many `ufunc`

s, which, under the hood, are typically implemented in C (a low-level compiled language) to improve their speed and efficiency.\n",
"A example `ufunc`

(`np.log()`

) is shown below:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0. , 0.38776553, 0.66647893, 0.88420242, 1.06289421,\n",
" 1.2144441 , 1.34602046, 1.46228027, 1.56642053, 1.66073121,\n",
" 1.7469089 , 1.82624565, 1.89974811, 1.96821591, 2.03229476,\n",
" 2.09251362, 2.14931122, 2.2030555 , 2.25405805, 2.30258509])"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import numpy as np\n",
"A = np.linspace(1.0, 10.0, 20)\n",
"np.log(A)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"`numpy`

module).\n", " (b) What is the shape of

`A*B`

, if the arrays `A`

and `B`

have shapes `(1,3,4)`

and `(2,5,3,1)`

?\n", "

`decimal`

package to display $e$ to 50 decimal places.`sumdigits(N)`

to compute the sum of the digits of a number. For example, `sumdigits(1234)`

would return `10`

(as 1+2+3+4=10).\n", "Use the function to compute the sum of the digits in your registration number.

\n", "

\n", "

`A B`

where \n",
"$$\n",
"A = \\begin{bmatrix} 5 & 6 & 2 \\\\ 1 & -1 & \\frac{3}{4} \\end{bmatrix} , \\quad \\quad\n",
"B = \\begin{bmatrix} 1 & 2 \\\\ 3 & -4 \\\\ 5 & 0 \\end{bmatrix}\n",
"$$\n",
"\n", "

`scramble`

function does.`scramble`

function encrypts a message using a keyword. It is a version of a Vigenère cipher, which is a method of encrypting alphabetic text by using a series of different Caesar ciphers based on the letters of a keyword (https://en.wikipedia.org/wiki/Vigenère_cipher). \n",
"\n",
"To see how this works, we can line up the characters in the plaintext with the characters in the keyword and the encrypted message, as below :\n",
"\n",
"```
\n",
"Hello everyone, blah blah blah.\n",
"aardvarkaardvarkaardvarkaardvar\n",
"Hecoj vferprie, blrk bckh sovh.\n",
"
```

\n",
"\n",
"The ciphertext is generated from the plaintext by using the characters in the keyword to move letters \"around the letter wheel\". Note that 'a' in the keyword leads to no change, whereas 'r' moves on by 17 (as 'r' is the 18th letter of the alphabet). Punctuation is not affected. \n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"`unscramble`

to reverse its effect. \n",
"\n",
"Use your function to decipher the following quote by a famous literary detective. From which novel is it taken?