Local vs Global
Completed
A global counter = 0 exists. Write increment() that adds 1 to the global counter. Read n, call it n times, and print the counter.
Input
One integer.
Output
The counter.
Example
Input
5
Output
5
Editor
Python
Hints
Assigning to a name inside a function makes it local unless you declare it global.
Solution explanation
global lets a function rebind a module-level name. Prefer returning values over changing globals in real programs.
Show solution
counter = 0
def increment():
global counter
counter += 1
for _ in range(int(input())):
increment()
print(counter)