Change my name!

Report a typo

John is writing a program. For some reason, he needs this program to store the name of a current user as well as be able to change it. He wrote a function change_name(), which changes a current username to a new one. However, when he executes the following code:

name = "John"

def change_name(new_name):
    name = new_name

change_name("Mary")
print(name)

the output is "John", so the name doesn’t change at all! Help him – write down the line he forgot to include in his function (only the line, not the whole code).

What can we do to make a variable change not only inside the function body but outside as well?
Enter a short text
___

Create a free account to access the full topic