-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogramming_exercises.qmd
130 lines (97 loc) · 2.39 KB
/
programming_exercises.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
---
format:
html:
output-file: "programming_exercises"
output-ext: "html"
editor: source
engine: knitr
filters:
- webr-teachr
- quiz-teachr
webr:
packages: ["reticulate"]
autoload-packages: false
---
```{r setup, include=FALSE}
library(reticulate)
use_python("/usr/bin/python3")
```
# Programming Exercises
This set of exercises is meant to test your knowledge of the concepts covered in block 2 of the course. All questions are Multiple Choice!
## Exercise 1
What is the evolutionary path of code, ideally?
:::{.quiz-multichoice}
- [ ] [module -> script -> function]{hint="x"}
- [X] [script -> functions -> package]{hint="o"}
- [ ] [functions -> package -> script]{hint="x"}
- [ ] [package -> class -> functions]{hint="x"}
:::
## Exercise 2
Which of these types of data is persistent?
:::{.quiz-multichoice}
- [ ] [data in memory]{hint="x"}
- [X] [data on disk (in a file)]{hint="o"}
- [X] [data in storage (e.g. in a database)]{hint="o"}
:::
## Exercise 3
Which of these file formats are interoperable?
:::{.quiz-multichoice}
- [X] [parquet]{hint="o"}
- [ ] [.RData]{hint="x"}
- [X] [.csv]{hint="o"}
- [ ] [.xlsx]{hint="x"}
- [ ] [.Dta]{hint="x"}
:::
## Exercise 4
Which of these file formats are binary?
:::{.quiz-multichoice}
- [ ] [.csv]{hint="x"}
- [X] [.pdf]{hint="o"}
- [ ] [.xml]{hint="x"}
- [ ] [.json]{hint="x"}
- [X] [.jpeg]{hint="o"}
<!-- TODO: check if this is true -->
:::
::: {.callout-caution}
## Your turn!
Think about what the underlying structure of the non-binary file formats might be.
:::
## Exercise 5
What are the good ways to store nested data on disk (in a file)?
:::{.quiz-multichoice}
- [X] [.json]{hint="o"}
- [ ] [.csv]{hint="x"}
- [X] [.yaml]{hint="o"}
- [X] [.xml]{hint="o"}
- [ ] [.xlsx]{hint="x"}
:::
## Exercise 6
Guess what the following code snippet in **Python** would return
```python
x = [1, 2, 3]
y = x
y.append(4)
print(x)
```
:::{.quiz-multichoice}
- [X] [list with elements 1-4]{hint="o"}
- [ ] [list with elements 1-3]{hint="x"}
- [ ] [list with element 4]{hint="x"}
:::
## Exercise 7
Guess what the following code snippet in **R** would return
```r
x <- c(1,2,3)
y <- x
y <- c(y,4)
print(x)
```
:::{.quiz-multichoice}
- [ ] [1 2 3 4]{hint="x"}
- [X] [1 2 3]{hint="o"}
- [ ] [4]{hint="x"}
:::
::: {.callout-caution}
## Your turn!
Try to replicate the above behavior of R in Python (the copying of variables). Hint: you can use shallow copies
:::