Skip to content

Commit d99e2ed

Browse files
committed
feat(code_structure): add mcq (#145)
1 parent bd36bb3 commit d99e2ed

1 file changed

Lines changed: 97 additions & 1 deletion

File tree

pages/guide/setup/code_structure.qmd

Lines changed: 97 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,102 @@ Normally, a mix of programming paradigms will be used.
341341

342342
## Test yourself
343343

344+
<div class="h3-tight"></div>
345+
346+
### Quiz
347+
348+
```{r}
349+
#| echo: false
350+
library(webexercises) # nolint: library_call_linter
351+
```
352+
353+
:::: {.python-content}
354+
355+
::: {.callout-note}
356+
357+
## Why do we recommend using functions and classes, instead of copying and pasting code?
358+
359+
```{r}
360+
#| output: asis
361+
#| echo: false
362+
cat(longmcq(c(
363+
answer = paste0(
364+
"Because small, reusable functions/classes make code more modular, ",
365+
"easier to read, test, and maintain, and avoid duplication."
366+
),
367+
paste0(
368+
"Because as long as logic is in functions or classes, it doesn't matter ",
369+
"if there is a lot of duplicated code."
370+
)
371+
)))
372+
```
373+
374+
:::
375+
376+
::: {.callout-note}
377+
378+
## In the Python `Patient` class, what is the purpose of the `__init__` method?
379+
380+
```{r}
381+
#| output: asis
382+
#| echo: false
383+
cat(longmcq(c(
384+
"To automatically run every hour and update all patients in the system.",
385+
answer = paste0(
386+
"It initialises a new `Patient` object by setting attributes such as ",
387+
"`patient_id`, `arrival_time`, and the initial `status`."
388+
),
389+
"To delete the patient from the queue when they arrive at the hospital."
390+
)))
391+
```
392+
393+
:::
394+
395+
::::
396+
397+
:::: {.r-content}
398+
399+
::: {.callout-note}
400+
401+
## Why do we recommend using functions, instead of copying and pasting code?
402+
403+
```{r}
404+
#| output: asis
405+
#| echo: false
406+
cat(longmcq(c(
407+
answer = paste0(
408+
"Because small, reusable functions make code more modular, ",
409+
"easier to read, test, and maintain, and avoid duplication."
410+
),
411+
paste0(
412+
"Because as long as logic is in functions, it doesn't matter ",
413+
"if there is a lot of duplicated code."
414+
)
415+
)))
416+
```
417+
418+
:::
419+
420+
::: {.callout-note}
421+
422+
## In the R `estimate_wait_time` example, what does the function return?
423+
424+
```{r}
425+
#| output: asis
426+
#| echo: false
427+
cat(longmcq(c(
428+
"A list containing duration, status, and a vector of results.",
429+
answer = "A single numeric value: the estimated total wait time.",
430+
"A data frame with one row per patient and their individual wait time."
431+
)))
432+
```
433+
434+
:::
435+
436+
::::
437+
438+
### Activity
439+
344440
::: {.python-content}
345441

346442
**Task: Refactor the provided script into a function or class and put it on GitHub**. To do this, you should:
@@ -468,7 +564,7 @@ print(results)
468564

469565
::::
470566

471-
:::: {.callout-tip title="Solutions" collapse="true"}
567+
:::: {.callout-tip title="Click to view solutions" collapse="true"}
472568

473569
::: {.python-content}
474570

0 commit comments

Comments
 (0)