-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathpop-quiz-on-understanding-scope.py
More file actions
28 lines (23 loc) · 1.03 KB
/
pop-quiz-on-understanding-scope.py
File metadata and controls
28 lines (23 loc) · 1.03 KB
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
'''
Pop quiz on understanding scope
50xp
In this exercise, you will practice what you've learned about scope in functions.
The variable num has been predefined as 5, alongside the following function definitions:
def func1():
num = 3
print(num)
def func2():
global num
double_num = num * 2
num = 6
print(double_num)
Try calling func1() and func2() in the shell, then answer the following questions:
-What are the values printed out when you call func1() and func2()?
-What is the value of num in the global scope after calling func1() and func2()?
Possible Answers
func1() prints out 3, func2() prints out 6, and the value of num in the global scope is 3.
func1() prints out 3, func2() prints out 3, and the value of num in the global scope is 3.
func1() prints out 3, func2() prints out 10, and the value of num in the global scope is 10.
func1() prints out 3, func2() prints out 10, and the value of num in the global scope is 6.
'''
# func1() prints out 3, func2() prints out 10, and the value of num in the global scope is 6.