Skip to content

Commit 09c8522

Browse files
committed
added test notebook for notebooks 1 - 4
1 parent 9ace409 commit 09c8522

File tree

6 files changed

+1515
-0
lines changed

6 files changed

+1515
-0
lines changed

.DS_Store

4 KB
Binary file not shown.
3.79 KB
Loading
Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"<figure>\n",
8+
" <IMG SRC=\"https://raw.githubusercontent.com/mbakker7/exploratory_computing_with_python/master/tudelft_logo.png\" WIDTH=250 ALIGN=\"right\">\n",
9+
"</figure>\n",
10+
"\n",
11+
"# Exploratory Computing with Python\n",
12+
"*Developed by Mark Bakker*"
13+
]
14+
},
15+
{
16+
"cell_type": "markdown",
17+
"metadata": {},
18+
"source": [
19+
"### Test for Notebooks 1 - 4"
20+
]
21+
},
22+
{
23+
"cell_type": "markdown",
24+
"metadata": {},
25+
"source": [
26+
"### <a name=\"ex1\"></a>Exercise 1\n",
27+
"\n",
28+
"Write a function that plots a square centered at the origin. The length of the side of the square is $L$. The input of the function is the length $L$. \n",
29+
"\n",
30+
"Next, write a loop that calls your function for $L$ going from 1 up to and including 5 with steps of 1. \n",
31+
"Use `plt.axis('scaled')` to make sure your squares look like squares and not rectangles."
32+
]
33+
},
34+
{
35+
"cell_type": "code",
36+
"execution_count": null,
37+
"metadata": {},
38+
"outputs": [],
39+
"source": []
40+
},
41+
{
42+
"cell_type": "markdown",
43+
"metadata": {},
44+
"source": [
45+
"<a href=\"#ex1answer\">Answer to Exercise 1</a>"
46+
]
47+
},
48+
{
49+
"cell_type": "markdown",
50+
"metadata": {},
51+
"source": [
52+
"### <a name=\"ex2\"></a>Exercise 2\n",
53+
"Write a function called `countsquares` that takes as input the filename of a file that consists of a bunch of numbers separated by spaces. Inside the function, you must first read the numbers from the filename and then you must determine how many of these numbers are a perfect square. A perfect square means that the root of the number is an integer (i.e., 1, 4, 16, 25, etc.). The function returns the number of perfect squares in the file. Note: to convert a number to an integer, use the `int` function. \n",
54+
"\n",
55+
"Demonstrate that your function works by using the file `numbers2016.txt` and execute the following line of code:\n",
56+
"\n",
57+
"`print(countsquares('numbers2016.txt'), 'numbers are perfect squares')`"
58+
]
59+
},
60+
{
61+
"cell_type": "code",
62+
"execution_count": null,
63+
"metadata": {},
64+
"outputs": [],
65+
"source": []
66+
},
67+
{
68+
"cell_type": "markdown",
69+
"metadata": {},
70+
"source": [
71+
"<a href=\"#ex2answer\">Answer to Exercise 2</a>"
72+
]
73+
},
74+
{
75+
"cell_type": "markdown",
76+
"metadata": {},
77+
"source": [
78+
"### <a name=\"ex3\"></a>Exercise 3\n",
79+
"The file `quiz_answers.dat` contains the result of a small multiple-choice quiz with 8 questions. Every row contains the 8 answers to the quiz of one of the students. Your job is to count how many students had the correct answer for each question. Write a double loop to compute the number of correct answers for each question and present the results in a bar graph. The correct answers for the 8 questions of the quiz are: `a b c d a b c d`"
80+
]
81+
},
82+
{
83+
"cell_type": "code",
84+
"execution_count": null,
85+
"metadata": {},
86+
"outputs": [],
87+
"source": []
88+
},
89+
{
90+
"cell_type": "markdown",
91+
"metadata": {},
92+
"source": [
93+
"<a href=\"#ex3answer\">Answer to Exercise 3</a>"
94+
]
95+
},
96+
{
97+
"cell_type": "markdown",
98+
"metadata": {},
99+
"source": [
100+
"### <a name=\"ex4\"></a> Exercise 4\n",
101+
"In the image below, you can see a possible future for the American flag if some of the American states leave the Union like the Brexit of England. Create a matrix of 13 rows and 20 columns. Create the red and white stripes plus the blue rectangle by assigning 0 (blue), 1 (white), and 2 (red) using at most three assignent statements. Show the matrix to the screen using the `bwr` colormap, and add the row of 9 stars by plotting markers with the `plt.plot` statement. \n",
102+
"\n",
103+
"Finally, add the line `plt.axis('image')` to your script, so the flag covers up your entire plot (no white banners). \n",
104+
"![](american_flag_brexit.png)"
105+
]
106+
},
107+
{
108+
"cell_type": "code",
109+
"execution_count": null,
110+
"metadata": {},
111+
"outputs": [],
112+
"source": []
113+
},
114+
{
115+
"cell_type": "markdown",
116+
"metadata": {},
117+
"source": [
118+
"<a href=\"#ex4answer\">Answer to Exercise 4</a>"
119+
]
120+
},
121+
{
122+
"cell_type": "markdown",
123+
"metadata": {},
124+
"source": [
125+
"### <a name=\"ex5\"></a>Exercise 5\n",
126+
"Write a function that computes the percentage of grades that is above a given value. The function takes as input arguments an array with grades between 1 and 10 and a minimum value and returns the precentage of grades (so between 0% and 100%) that are above or equal to that value. Demonstrate that your function works by loading the grades in the file `schoolgrades2016.txt` and print the result of the function to the screen, given a minimum value of 7."
127+
]
128+
},
129+
{
130+
"cell_type": "code",
131+
"execution_count": null,
132+
"metadata": {},
133+
"outputs": [],
134+
"source": []
135+
},
136+
{
137+
"cell_type": "markdown",
138+
"metadata": {},
139+
"source": [
140+
"<a href=\"#ex5answer\">Answer to Exercise 5</a>"
141+
]
142+
},
143+
{
144+
"cell_type": "markdown",
145+
"metadata": {},
146+
"source": [
147+
"### Brief answers"
148+
]
149+
},
150+
{
151+
"cell_type": "markdown",
152+
"metadata": {},
153+
"source": [
154+
"<a name=\"ex1answer\">Answer to Exercise 1</a>\n",
155+
"\n",
156+
"You probably know what this should look like\n",
157+
"\n",
158+
"<a href=\"#ex1\">Back to Exercise 1</a>\n",
159+
"\n",
160+
"<a name=\"ex2answer\">Answer to Exercise 2</a>\n",
161+
"\n",
162+
"93\n",
163+
"\n",
164+
"<a href=\"#ex2\">Back to Exercise 2</a>\n",
165+
"\n",
166+
"<a name=\"ex3answer\">Answer to Exercise 3</a>\n",
167+
"\n",
168+
"Q1: 4, Q2: 4, Q3: 5, Q4:3, Q5:5, Q6:5, Q7:4, Q8:4\n",
169+
"\n",
170+
"<a href=\"#ex3\">Back to Exercise 3</a>\n",
171+
"\n",
172+
"<a name=\"ex4answer\">Answer to Exercise 4</a>\n",
173+
"\n",
174+
"Your graph should look like the provide figure\n",
175+
"\n",
176+
"<a href=\"#ex4\">Back to Exercise 4</a>\n",
177+
"\n",
178+
"<a name=\"ex5answer\">Answer to Exercise 5</a>\n",
179+
"\n",
180+
"31.3\n",
181+
"\n",
182+
"<a href=\"#ex5\">Back to Exercise 5</a>"
183+
]
184+
}
185+
],
186+
"metadata": {
187+
"anaconda-cloud": {},
188+
"kernelspec": {
189+
"display_name": "Python 3",
190+
"language": "python",
191+
"name": "python3"
192+
},
193+
"language_info": {
194+
"codemirror_mode": {
195+
"name": "ipython",
196+
"version": 3
197+
},
198+
"file_extension": ".py",
199+
"mimetype": "text/x-python",
200+
"name": "python",
201+
"nbconvert_exporter": "python",
202+
"pygments_lexer": "ipython3",
203+
"version": "3.7.0"
204+
}
205+
},
206+
"nbformat": 4,
207+
"nbformat_minor": 1
208+
}

0 commit comments

Comments
 (0)