Challenge 2: Updating Outer Scope Values
Let’s look at another coding challenge.
Problem Statement
You must implement the update_var()
function that takes in a value
as parameter, and updates the value of the var
variable in the outer scope to the one supplied as a parameter. Return the updated var
at the end. If var
doesn’t exist in the outer scope, your function should create it.
Sample input #1
var = 5
print(update_var(7))
Sample output #1
7
Sample input #2
# Assuming var doesn't exist
# var = 5
print(update_var(8))
Sample output #2
8
Coding challenge
Get hands-on with 1400+ tech skills courses.