Rullst AcademyRullst Academy/Lesson
Python: from first line to project · Lesson 07 / 12

One function, one responsibility

How much time remains? This question appears repeatedly. A function names the rule so we can reuse and test it.

Learning paths10 min

Let's discover together

  1. 1

    def remaining(limit, used): defines the function. limit and used are parameters: names receiving values when it is called.

  2. 2

    remaining(30, 10) passes two arguments: 30 for limit, 10 for used. return limit - used returns 20 to the caller. Defining the function alone does not execute its body.

  3. 3

    print displays a message; return provides a value that another part of the program can use. A function without an explicit return returns None.

  4. 4

    Our function only subtracts; it does not yet check whether used exceeds limit. Documenting this limit avoids promising validation the code does not perform.

✦
YOUR MISSION

Define and call functions; distinguish parameters, arguments, return and printing.

Now it's your turn

Discovery workshop

Read, predict, check

Compare the two versions. Show result reveals a prepared output: this panel does not run Python. Then practise with the activity file.
Mini experiment

Learning simulation: compare cards and check your predictions. The browser is not compiling Rust or starting a server.

def remaining(limit, used):
    return limit - used

print(remaining(30, 10))
Build your answers and check when you are ready.
A moment to understand

Why can returning a result be better than only displaying it?

I need a hint

Ask who needs to receive the result.

Loading your journey…

Take it with you

Write a double(minutes) function returning twice the value. Call it with 0, 5 and 12. Record expected outputs before running.

PYTHON · .py

Your Python workbench

Here you read and predict prepared outputs. To run the actual code, download the activity file, edit it on your computer and use Python. Rullst Academy grades lesson answers; it does not verify local execution.

Save and run

Extract the activity ZIP into its own folder. Open a terminal there and use your system’s command. If downloading your edited file separately, use its actual name in the command. Save before running again.

Windows
python lesson.py
macOS / Ubuntu
python3 lesson.py
My files and GitHub

The editor keeps a local draft and can send a .py file to GitHub with your confirmation. Download your edited code to preserve it. The ZIP is starter material; for the final project, also publish data and test files following PUBLISH.md.

At your own pace

My files and GitHub

Every lesson can become your own record: code, notes or a practice plan. Saving a file to GitHub is optional and does not change your XP.

Student guide

The editor and downloads open when this lesson is available to your account. Check access below or return to the track map.

Checking your access to this lesson…

Rullstpetbot

AI can make mistakes. Check the lesson material.