Skip to content

Commit bdd446e

Browse files
committed
Update crash course and pset
1 parent b982307 commit bdd446e

3 files changed

Lines changed: 248 additions & 34 deletions

File tree

chapters/crash_course/functions_and_classes.ipynb

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"## 1) Basic function syntax\n",
2424
"\n",
2525
"A function is defined with `def`.\n",
26-
"It can receive inputs (parameters) and return an output with `return`.\n"
26+
"It can receive inputs and (optionally) return an output with `return`.\n"
2727
]
2828
},
2929
{
@@ -566,21 +566,6 @@
566566
"- define classes and create instances,\n",
567567
"- use constructors, attributes, and methods.\n"
568568
]
569-
},
570-
{
571-
"cell_type": "markdown",
572-
"id": "69e3825d",
573-
"metadata": {},
574-
"source": [
575-
"## 12) Mini practice\n",
576-
"\n",
577-
"Try these tasks:\n",
578-
"1. Write a function `cube(x)` that returns `x**3`.\n",
579-
"2. Write a function with one required argument and one default argument.\n",
580-
"3. Write a function that returns two values and unpack them.\n",
581-
"4. Use `lambda` as a `key` to sort a list of tuples by the first item.\n",
582-
"5. Create a class with two attributes and one method, then create one instance and call the method.\n"
583-
]
584569
}
585570
],
586571
"metadata": {

chapters/crash_course/visualising_data.ipynb

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
"metadata": {},
77
"source": [
88
"(sec:visualising_data)=\n",
9-
"# Visualising Data with Matplotlib\n",
9+
"# Visualising Data\n",
1010
"\n",
11-
"Matplotlib is one of the main plotting libraries in Python.\n",
11+
"[Matplotlib](https://matplotlib.org) is one of the main plotting libraries in Python.\n",
1212
"It works especially well with NumPy, because NumPy arrays store numerical data in a form that is easy to plot.\n",
1313
"\n",
1414
"## Learning goals\n",
@@ -565,21 +565,6 @@
565565
"- add labels, titles, limits, and legends,\n",
566566
"- use `fig, ax` for advanced axis control and subplot layouts.\n"
567567
]
568-
},
569-
{
570-
"cell_type": "markdown",
571-
"id": "98129841",
572-
"metadata": {},
573-
"source": [
574-
"## 10) Mini practice\n",
575-
"\n",
576-
"Try these tasks:\n",
577-
"1. Plot a simple list of five values with markers only.\n",
578-
"2. Create an `x` grid with `np.arange(0, 5, 0.5)` and plot `np.sin(x)`.\n",
579-
"3. Add `xlabel`, `ylabel`, `title`, `xlim`, and `ylim` to one plot.\n",
580-
"4. Plot `sin(x)` and `cos(x)` in one figure with different styles and a legend.\n",
581-
"5. Build a 2x2 subplot figure and place one function in each panel.\n"
582-
]
583568
}
584569
],
585570
"metadata": {

chapters/problem_sets/pset_0.ipynb

Lines changed: 245 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,134 @@
173173
"# your code here\n"
174174
]
175175
},
176+
{
177+
"cell_type": "markdown",
178+
"id": "fbb209bb",
179+
"metadata": {},
180+
"source": [
181+
"## Exercise 0.2: Functions and Classes\n",
182+
"\n",
183+
"**(a)** Write a function `cube(x)` that returns `x**3`."
184+
]
185+
},
186+
{
187+
"cell_type": "code",
188+
"execution_count": null,
189+
"id": "543558e8",
190+
"metadata": {},
191+
"outputs": [],
192+
"source": [
193+
"# your code here\n",
194+
"\n",
195+
"\n",
196+
"\n",
197+
"\n",
198+
"\n",
199+
"\n"
200+
]
201+
},
202+
{
203+
"cell_type": "markdown",
204+
"id": "3c761c7d",
205+
"metadata": {},
206+
"source": [
207+
"**(b)** Write a function with one required argument and one default argument."
208+
]
209+
},
210+
{
211+
"cell_type": "code",
212+
"execution_count": null,
213+
"id": "931217b3",
214+
"metadata": {},
215+
"outputs": [],
216+
"source": [
217+
"# your code here\n",
218+
"\n",
219+
"\n",
220+
"\n",
221+
"\n",
222+
"\n",
223+
"\n"
224+
]
225+
},
226+
{
227+
"cell_type": "markdown",
228+
"id": "49d5e372",
229+
"metadata": {},
230+
"source": [
231+
"**(c)** Write a function that returns two values and unpack them."
232+
]
233+
},
234+
{
235+
"cell_type": "code",
236+
"execution_count": null,
237+
"id": "1c7490ac",
238+
"metadata": {},
239+
"outputs": [],
240+
"source": [
241+
"# your code here\n",
242+
"\n",
243+
"\n",
244+
"\n",
245+
"\n",
246+
"\n",
247+
"\n"
248+
]
249+
},
250+
{
251+
"cell_type": "markdown",
252+
"id": "3c109800",
253+
"metadata": {},
254+
"source": [
255+
"**(d)** Use `lambda` as a `key` to sort a list of tuples by the first item."
256+
]
257+
},
258+
{
259+
"cell_type": "code",
260+
"execution_count": null,
261+
"id": "774d7251",
262+
"metadata": {},
263+
"outputs": [],
264+
"source": [
265+
"# your code here\n",
266+
"\n",
267+
"\n",
268+
"\n",
269+
"\n",
270+
"\n",
271+
"\n"
272+
]
273+
},
274+
{
275+
"cell_type": "markdown",
276+
"id": "e45cb3e9",
277+
"metadata": {},
278+
"source": [
279+
"**(e)** Create a class with two attributes and one method, then create one instance and call the method."
280+
]
281+
},
282+
{
283+
"cell_type": "code",
284+
"execution_count": null,
285+
"id": "59aa7657",
286+
"metadata": {},
287+
"outputs": [],
288+
"source": [
289+
"# your code here\n",
290+
"\n",
291+
"\n",
292+
"\n",
293+
"\n",
294+
"\n",
295+
"\n"
296+
]
297+
},
176298
{
177299
"cell_type": "markdown",
178300
"id": "11ddb593",
179301
"metadata": {},
180302
"source": [
181-
"## Exercise 0.2: Numerical Programming\n",
303+
"## Exercise 0.3: Numerical Programming\n",
182304
"\n",
183305
"**(a)** Create a grid from 0 to 2 with 9 points using `linspace`, then compute `np.cos(grid)`."
184306
]
@@ -294,6 +416,128 @@
294416
"\n",
295417
"\n"
296418
]
419+
},
420+
{
421+
"cell_type": "markdown",
422+
"id": "f8d7d211",
423+
"metadata": {},
424+
"source": [
425+
"## Exercise 0.4: Visualising Data\n",
426+
"\n",
427+
"**(a)** Plot a simple list of five values with markers only."
428+
]
429+
},
430+
{
431+
"cell_type": "code",
432+
"execution_count": null,
433+
"id": "8bdceae4",
434+
"metadata": {},
435+
"outputs": [],
436+
"source": [
437+
"# your code here\n",
438+
"\n",
439+
"\n",
440+
"\n",
441+
"\n",
442+
"\n",
443+
"\n"
444+
]
445+
},
446+
{
447+
"cell_type": "markdown",
448+
"id": "28533e2a",
449+
"metadata": {},
450+
"source": [
451+
"**(b)** Create an `x` grid with `np.arange(0, 5, 0.5)` and plot `np.sin(x)`."
452+
]
453+
},
454+
{
455+
"cell_type": "code",
456+
"execution_count": null,
457+
"id": "370f3669",
458+
"metadata": {},
459+
"outputs": [],
460+
"source": [
461+
"# your code here\n",
462+
"\n",
463+
"\n",
464+
"\n",
465+
"\n",
466+
"\n",
467+
"\n"
468+
]
469+
},
470+
{
471+
"cell_type": "markdown",
472+
"id": "99a2981e",
473+
"metadata": {},
474+
"source": [
475+
"**(c)** Add `xlabel`, `ylabel`, `title`, `xlim`, and `ylim` to one plot."
476+
]
477+
},
478+
{
479+
"cell_type": "code",
480+
"execution_count": null,
481+
"id": "8c036dcd",
482+
"metadata": {},
483+
"outputs": [],
484+
"source": [
485+
"# your code here\n",
486+
"\n",
487+
"\n",
488+
"\n",
489+
"\n",
490+
"\n",
491+
"\n"
492+
]
493+
},
494+
{
495+
"cell_type": "markdown",
496+
"id": "874ab4b7",
497+
"metadata": {},
498+
"source": [
499+
"**(d)** Plot `sin(x)` and `cos(x)` in one figure with different styles and a legend."
500+
]
501+
},
502+
{
503+
"cell_type": "code",
504+
"execution_count": null,
505+
"id": "4b993e3b",
506+
"metadata": {},
507+
"outputs": [],
508+
"source": [
509+
"# your code here\n",
510+
"\n",
511+
"\n",
512+
"\n",
513+
"\n",
514+
"\n",
515+
"\n"
516+
]
517+
},
518+
{
519+
"cell_type": "markdown",
520+
"id": "535176b1",
521+
"metadata": {},
522+
"source": [
523+
"**(e)** Build a 2x2 subplot figure and place one function in each panel."
524+
]
525+
},
526+
{
527+
"cell_type": "code",
528+
"execution_count": null,
529+
"id": "c4186594",
530+
"metadata": {},
531+
"outputs": [],
532+
"source": [
533+
"# your code here\n",
534+
"\n",
535+
"\n",
536+
"\n",
537+
"\n",
538+
"\n",
539+
"\n"
540+
]
297541
}
298542
],
299543
"metadata": {

0 commit comments

Comments
 (0)