Skip to content

Commit b97ef44

Browse files
committed
Some rationalisation of 2012 exam.
1 parent a1a8af3 commit b97ef44

File tree

2 files changed

+110
-0
lines changed

2 files changed

+110
-0
lines changed

notebook/python_class_test_2012.ipynb

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
{
2+
"metadata": {
3+
"name": "",
4+
"signature": "sha256:be7bd3a61a77d22009003a296181408c2ffea78ec6a2584fcdb0dd2c2079ed7e"
5+
},
6+
"nbformat": 3,
7+
"nbformat_minor": 0,
8+
"worksheets": [
9+
{
10+
"cells": [
11+
{
12+
"cell_type": "heading",
13+
"level": 1,
14+
"metadata": {},
15+
"source": [
16+
"2.18 Programming for Geoscientists class test 2012. "
17+
]
18+
},
19+
{
20+
"cell_type": "heading",
21+
"level": 2,
22+
"metadata": {},
23+
"source": [
24+
"Note: 2013 was the first time the exam was run using iPython rather than using a text editor and the command line. This iPython version was created for the 2013 class so that they would know what to expect."
25+
]
26+
},
27+
{
28+
"cell_type": "markdown",
29+
"metadata": {},
30+
"source": [
31+
"#Test instructions\n",
32+
"\n",
33+
"* This test contains **5** questions each of which should be answered.\n",
34+
"* Write your program in a Python cell just under each question.\n",
35+
"* You can write an explanation of your solution as comments in your code.\n",
36+
"* In each case your solution program must fulfil all of the instructions - please check the instructions carefully and double check that your program fulfils all of the given instructions.\n",
37+
"* Save your work regularly.\n",
38+
"* At the end of the test you should email your IPython notebook document (i.e. this document) to [Gerard J. Gorman](http://www.imperial.ac.uk/people/g.gorman) at g.gorman@imperial.ac.uk"
39+
]
40+
},
41+
{
42+
"cell_type": "markdown",
43+
"metadata": {},
44+
"source": [
45+
"**1.** Ignore this question from 2012 as it deals with material no longer covered."
46+
]
47+
},
48+
{
49+
"cell_type": "markdown",
50+
"metadata": {},
51+
"source": [
52+
"**2.** Write a program, that creates a *list* $t$ with 6 values, 0.1, 0.2, ..., 0.6. Compute a corresponding *list* $y$ of $y(t)$ values using the formula:\n",
53+
"$$y(t) = v_0t \u2212 gt^2,$$\n",
54+
"where $v_0=6.0$ and $g=9.8$.\n",
55+
"\n",
56+
"* Store these two lists, t and y, in a new list t1.\n",
57+
"* Write out a table with a column of t and a column of y values by traversing the data in the nested t1 list.\n",
58+
"* You may use list or NumPy array for t and y.\n",
59+
"* Print out a table header with the column names \u2019t\u2019 and \u2019y\u2019.\n",
60+
"* For printing the table, iterate the nested list t1, do not access the previously computed t and y lists directly.\n",
61+
"* Print out the table t1 using format specifiers so that the columns are aligned."
62+
]
63+
},
64+
{
65+
"cell_type": "markdown",
66+
"metadata": {},
67+
"source": [
68+
"**3.** The factorial of n, written as n!, is defined as:\n",
69+
"$$n! = n(n \u2212 1)(n \u2212 2)...2\\cdot1,$$\n",
70+
"with the special cases\n",
71+
"$$1! = 1, 0! = 1.$$\n",
72+
"For example, $4! = 4\\cdot3\\cdot2\\cdot1 = 24$, and $2! = 2\\cdot1 = 2$.\n",
73+
"\n",
74+
"* Write a function fact(n) that returns $n!$. You **must** not use the *fact* function from the math module.\n",
75+
"* Return 1 immediately if $x$ is 1 or 0, otherwise use a loop to compute $n!$.\n",
76+
"* The function must be called *fact* and take a single argument called n.\n",
77+
"* The software should check that the supplied value is a non-negative integer. If it is not, raise a ValueError exception."
78+
]
79+
},
80+
{
81+
"cell_type": "markdown",
82+
"metadata": {},
83+
"source": [
84+
"**4.** A table of temperatures and densities, in units of degrees ($C$) and $kg/m^3$, are given in the file *data/density\\_air.dat*\n",
85+
"Write a program that reads in the data from file into a list for temperature (first column) and density (second column) and plots the variation of density against temperature.\n",
86+
"\n",
87+
"* The input file contains blank lines and lines starting with a \u2019#\u2019, which you must ignore when reading in the data.\n",
88+
"* You may use list or NumPy array for temperature and density.\n",
89+
"* Plot the variation of density against temperature.\n",
90+
"* Label the x axis \"Temperature (Celsius)\" and the y axis \"Density ($kg/m^3$)\".\n",
91+
"* Use the plot title \"Density of air at different temperatures, at 1 atm pressure\".\n",
92+
"* Display a legend with the label \u2019Air\u2019."
93+
]
94+
},
95+
{
96+
"cell_type": "markdown",
97+
"metadata": {},
98+
"source": [
99+
"**5.** Based on the data in the file *data/constants.txt*, make a dictionary where the keys are the names of the physical constant and the values are a tuple containing the numerical value and the units.\n",
100+
"\n",
101+
"* Use a Python dictionary to store the data.\n",
102+
"* All numerical values should be of type float.\n",
103+
"* Print out the dictionary without any formatting."
104+
]
105+
}
106+
],
107+
"metadata": {}
108+
}
109+
]
110+
}

0 commit comments

Comments
 (0)