Self-assessment quiz
Presentation & objectives
The following quizzes are here to help you check that you understood the articles you had to study. They are provided for self-assessment and will not be graded or stored.
Don’t hesitate to reach out on the Discord server for any precision/explanation!
Quizzes
---
secondary_color: lightgray
---
## Utility of functions
---
shuffle_answers: false
---
Why the use of functions is so important?
> Some hint
- [ ] It makes your code faster to run.
- [x] It makes your code more reusable.
- [x] It makes your code easier to read.
- [x] It makes your code easier to test.
## Components of a function
---
shuffle_answers: false
---
What is true?
> Some hint
- [ ] A python function always returns a value
- [X] A Python function can return multiple values
- [ ] Python executes a function when the `def` keyword is met
- [X] A function can be passed as an argument of another function
## Calling functions
---
shuffle_answers: true
---
Which call(s) is(are) correct considering the following function prototype?
```python
def random_values(nb_points: int, minv: int, maxv: int) -> List[int]:
"""Returns a list of n random integers between minv and maxv (inclusive).
Args:
nb_points (int): The number of values to generate.
minv (int): The minimum value for the random integers.
maxv (int): The maximum value for the random integers.
Returns:
List[int]: A list of n random integers between minv and maxv (inclusive).
"""
```
> Some hint
- [ ] ```python
random_values(5, 0, 100) -> a
```
- [x] ```python
lrv = random_values(5, 0, 100)
```
- [ ] ```python
lrv = random_values()
```
- [ ] ```python
random_values('100', '0', '100')
```
- [ ] ```python
random_values(100)
```
- [ ] ```python
lrv = random_values[5, 0, 100]
```
## Parameters
---
shuffle_answers: true
---
What is the output of the following code?
```python
def func(*args):
s = ""
for i in args:
s += str(i) + "-"
print(s)
func('a', 3, 0.3)
```
> Some hint
- [X] ```python
a-3-0.3-
```
- [X] ```python
a-
3-
0.3-
```
- [ ] ```python
0.3-
```
- [ ] An error is returned due to argument mismatch
## Visibility of variables
---
shuffle_answers: true
---
What is the output of the following code?
```python
x = 30
def myfunc():
x = 20
print("D1:", x)
myfunc()
print("D2:", x)
```
> Some hint
- [X] `D1: 20` et `D2: 30`
- [ ] `D1: 30` et `D2: 30`
- [ ] `D1: 20` et `D2: 20`
## Modularity
---
shuffle_answers: true
---
What is the name of the python package installer?
> Some hint
- [ ] *mypy*
- [ ] *pyins*
- [X] *pip*