Мой профиль
ACTIVITY 38 / 50

Where a variable lives

Try as many times as you need

Let’s understand

A variable created inside a function normally belongs to that call. It is local. The same name outside may hold a different value. Changing the local value does not automatically overwrite the outer one. Use return to send a calculated result out. Here we deliberately reuse a name to make the boundary visible.

Listen to the explanation

Example

name = "base"
def report():
    name = "rover"
    return name
print(report())
print(name)
YOUR MISSION

Keep energy = 100 outside. In test, create local energy = 3 and return it. Print test(), then the outer energy: 3 and 100 on separate lines.

I need a hint

Define def test(). Do not indent the outer variable.

How to find an error
  1. Read the last line of the error message.
  2. Find the indicated line. Check quotes, parentheses and indentation.
  3. Change one thing and run again.

main.py

4 spaces

Your draft stays in this browser.

Result

Python
Your program’s output will appear here. Click Run.