forked from realpython/materials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext.py
More file actions
34 lines (26 loc) · 715 Bytes
/
Copy pathcontext.py
File metadata and controls
34 lines (26 loc) · 715 Bytes
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
total = 100
def decrement_by(number):
"""Decrement the global total variable by a given number.
>>> local_total = decrement_by(50)
>>> local_total
50
Changes to total don't affect the code's global scope
>>> total
100
"""
global total
total -= number
return total
def increment_by(number):
"""Increment the global total variable by a given number.
The initial value of total's shallow copy is 50
>>> increment_by(10)
60
The local_total variable is not defined in this test
>>> local_total
Traceback (most recent call last):
NameError: name 'local_total' is not defined
"""
global total
total += number
return total