Skip to content

Commit 37cecef

Browse files
committed
Class test 2014.
1 parent b97ef44 commit 37cecef

File tree

1 file changed

+136
-0
lines changed

1 file changed

+136
-0
lines changed

notebook/python_class_test_2014.ipynb

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
{
2+
"metadata": {
3+
"name": "",
4+
"signature": "sha256:3a1a95e9862e43bf74fc3050daba15a91b9955cdcf74c67b1d8a4a6044df811c"
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 - 14:00-16:00 18th December 2014\n"
17+
]
18+
},
19+
{
20+
"cell_type": "markdown",
21+
"metadata": {},
22+
"source": [
23+
"#Test instructions\n",
24+
"\n",
25+
"* This test contains **5** questions each of which should be answered.\n",
26+
"* Write your program in a Python cell just under each question.\n",
27+
"* You can write an explanation of your solution as comments in your code.\n",
28+
"* 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",
29+
"* Save your work regularly.\n",
30+
"* 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"
31+
]
32+
},
33+
{
34+
"cell_type": "markdown",
35+
"metadata": {},
36+
"source": [
37+
"**Question 1** \n",
38+
"\n",
39+
"* Correct the 5 errors in the following program.\n",
40+
"* In each case add a comment explaining the error and the fix.\n",
41+
"* To verify your answer remember that $sin ^2( x ) + cos ^2( x ) = 1$."
42+
]
43+
},
44+
{
45+
"cell_type": "code",
46+
"collapsed": false,
47+
"input": [
48+
"from math import sin, cos\n",
49+
"x = pi /4\n",
50+
"1_val = sin^2( x ) + cos^2( x )\n",
51+
"print 1_VAL"
52+
],
53+
"language": "python",
54+
"metadata": {},
55+
"outputs": []
56+
},
57+
{
58+
"cell_type": "markdown",
59+
"metadata": {},
60+
"source": [
61+
"**Question 2**\n",
62+
"\n",
63+
"* Create a python list containing 101 evenly spaced values between -1.0 and 1.0.\n",
64+
"* Show how this could be more efficently done using NumPy.\n",
65+
"* Print out the values using a formatted print statement."
66+
]
67+
},
68+
{
69+
"cell_type": "code",
70+
"collapsed": false,
71+
"input": [],
72+
"language": "python",
73+
"metadata": {},
74+
"outputs": []
75+
},
76+
{
77+
"cell_type": "markdown",
78+
"metadata": {},
79+
"source": [
80+
"**Question 3**\n",
81+
"\n",
82+
"* a. Write a python function that evaluates the equation below for input variables $x$ and $t$: $$f(x, t) = e^{-(x-3t)^2} \\sin \\left( 3\\pi \\left( x-t \\right) \\right)$$\n",
83+
"* b. Generate an array of $x$ values in the range $[-3.0, 10]$.\n",
84+
"* c. Using this array of x values, plot the function for $t=0.0$, $t=1.0$ and $t=2.0$."
85+
]
86+
},
87+
{
88+
"cell_type": "code",
89+
"collapsed": false,
90+
"input": [],
91+
"language": "python",
92+
"metadata": {},
93+
"outputs": []
94+
},
95+
{
96+
"cell_type": "markdown",
97+
"metadata": {},
98+
"source": [
99+
"**Question 4**\n",
100+
"\n",
101+
"* Write a program to read the data file *seismic.dat* and store the magnitude of the earthquakes (*i.e.* the last column) in an numpy array.\n",
102+
"* How many earthquakes are there above magnitude 6.0?"
103+
]
104+
},
105+
{
106+
"cell_type": "code",
107+
"collapsed": false,
108+
"input": [],
109+
"language": "python",
110+
"metadata": {},
111+
"outputs": []
112+
},
113+
{
114+
"cell_type": "markdown",
115+
"metadata": {},
116+
"source": [
117+
"**Question 5** The file *human_evolution.txt* holds information about various human species and their hight, weight, and brain volume. \n",
118+
"\n",
119+
"* Write a program that reads this file and stores the data in a python dictionary humans.\n",
120+
"* The dictionary key should correspond to the specie name (e.g., \u201chomo erectus\u201d), and the value should be a list containing the corresponding data. For example, humans[\"H. habilis\"] should give [\"2.2 - 1.6\", \"1.0 \u2013 1.5\", \"33 \u2013 55\", \"660\"].\n",
121+
"* Write out the humans dictionary in a formatted tabular form."
122+
]
123+
},
124+
{
125+
"cell_type": "code",
126+
"collapsed": false,
127+
"input": [],
128+
"language": "python",
129+
"metadata": {},
130+
"outputs": []
131+
}
132+
],
133+
"metadata": {}
134+
}
135+
]
136+
}

0 commit comments

Comments
 (0)