Local or Global?
Python
25 pts
Local or Global?
Write two functions that use the global variable city = "Asmara":
trip()creates a local variablecity = "Keren"and printsInside: Keren. It must not change the globalcity.move()uses theglobalkeyword to change the globalcityto"Massawa".
The calls and prints are already written. Expected output:
Inside: Keren Outside: Asmara Outside: Massawa
Checklist
- Define
trip()with a localcitythat it prints, without changing the globalcity. - Define
move()so it changes the globalcityto"Massawa". - Run the program so the given calls print all three lines.
🔑 Solution
If you view the solution before passing, you earn half points for this exercise. You still need to type it and press Check to finish.
How it works, step by step
Point at a step to highlight its lines. Type the solution yourself and press Check answer to finish.
