Complete the code to modify the global variable inside the function.
count = 0 def increment(): global [1] count += 1 increment() print(count)
The global keyword tells Python to use the global variable count inside the function, so it can be modified.
Complete the code to correctly update the global variable inside the function.
total = 10 def add_five(): global [1] total += 5 add_five() print(total)
The function uses global total to modify the global variable total by adding 5.
Fix the error by completing the code to modify the global variable inside the function.
counter = 5 def reset(): [1] counter counter = 0 reset() print(counter)
nonlocal instead of global when the variable is global.The global keyword is needed to tell Python that counter inside the function refers to the global variable, so it can be reset.
Fill in the blank to correctly modify two global variables inside the function.
x = 1 y = 2 def update(): [1] x, y x += 10 y += 20 update() print(x, y)
nonlocal instead of global.Use global for both variables to modify them inside the function.
Fill in the blank to correctly use the global keyword and modify variables inside the function.
a = 5 b = 10 c = 15 def change_values(): [1] a, b, c a += 1 b += 2 c += 3 change_values() print(a, b, c)
The global keyword is used to declare variables a, b, and c as global so they can be modified inside the function.