ACTIVITY 47 / 50
Try as many times as you needYour own module
Let’s understand
An ordinary .py file can also be a module. This workshop includes helpers.py with a function called triple. Import it just as you imported a function from math. Modules let one part of a program reuse another.
Listen to the explanation
Example
# helpers.py
def triple(n):
return n * 3Import triple from helpers. Read a number and print triple of it.
I need a hint
Use from helpers import triple.
How to find an error
- Read the last line of the error message.
- Find the indicated line. Check quotes, parentheses and indentation.
- Change one thing and run again.
helpers.py
def triple(n):
return n * 3
main.py
4 spaces
Your draft stays in this browser.
Result
PythonYour program’s output will appear here. Click Run.
Мой профиль