Week 5 Unit 4: Self-test

05. December 2024

Question 1

Which of the following statements about variables in functions are correct?

Note: There are 3 correct answers to this question.


Using the keyword "global", variables defined outside of the function can be made visible inside the function.
The terms local and global are good for communication, but do not have any semantics.
Local variables are not visible outside of the function.
Variables in functions have either a global or a local scope.
If there is a global and a local variable with the same name, an error is triggered.

Question 2

What is the outcome of the following program?

week5 unit4 f2

week5 unit4 f2 1
week5 unit4 f2 2
week5 unit4 f2 3
UnboundLocalError


< Previous unit | Next unit > | Course Overview