Save / load workspace

Save your lab results on this server for 48 hours. Use the token to continue on another device. Anyone who knows the token can open your workspace.

Save workspace

A name is required when you first save and is then permanently bound to this workspace. Task values, entries and progress are saved together.

Load workspace

New workspace

Start with empty results and a name of your choice. Previously saved tokens remain valid until they expire. Unsaved changes in this tab will be discarded.

Saving also transfers any included measurement files and analysis videos to this server. Running simulations are saved as a set of results and displayed in a paused state when loaded.

Module 1 — What is a function?

A reusable, named code block.

Definition

One Function bundles a small exercise under one name. You define it once and can then call it as often as you like - if necessary with different values each time.

Syntax:

def <name>(<parameter>):
    <Anweisungen>
    return <wert>

The line def …: means Functional head, everything below (indented) is the Functional fuselage. Without a call, nothing happens — the definition itself guides the code not out.

Example 1.1 — define and call a function

Loading Python…
Output

    

Module 2 — Parameters & Arguments

Enter values into the function.

Parameter

The names in brackets def quadrat(zahl): hot water Parameter. They are local Variables that are refilled with each call Arguments that the caller passes.

A function can have any number of parameters — separated by commas.

Example 2.1 — a parameter

Loading Python…
Output

    

Example 2.2 — two parameters

Loading Python…
Output

    

Module 3 — return: return values

Functions deliver results — the caller catches them.

Identification

With return <wert> the function returns a result to the location where it was called. There you save the result in a Variable and keep working with it.

The function returns its value using return The caller stores the value and, if needed, outputs it using print() out.

Definition and call

def quadrat(zahl):
    return zahl * zahl

ergebnis = quadrat(6)
print(ergebnis)

The call appears below the function definition without indentation. Here you practise parameters and return values. In the next module, “Main block”, you learn how to prevent calls when a file is imported.

Example 3.1 — Store return in variable

Loading Python…
Output

    

Without return

Missing that return, the function returns implicitly None — so it returns “nothing.” This is usually not wanted.

Module 4 — Multiple return values

Tuple unpacking on the call side.

Identification

A function is allowed behind return Specify multiple values, separated by commas: return a, b. Python packages them into one Tuple. On the call side, they are distributed across a suitable number of variables:

summe, produkt = rechner(a, b)

For example, you can B. Area and Scope or Min and Deliver Max in one call.

Example 4.1 — catching two returns

Loading Python…
Output

    

TipRule of style

Define the function first. Then place input, function calls and output below the definition without indentation.

NoteTwo types of exercises

The programming tasks are deliberately mixed:

  • Reading-exercises (parts 1, 2, 4, 5): Below the function definition, read the values using input() a (introduced in the module Variables), call the function and return it print() out. The check automatically feeds in the input and compares your output character by character — therefore output exactly what is required.
  • Definition-exercises (Part 3, 6): Here you define only the function — none input(), none print(). The check calls your function itself with fixed values and checks them Return. So you see: you don't have to read everything in, defining the function is the core.

Sources & further literature

Where the knowledge imparted here is officially documented.

Official Python documentation

Tutorials & Manuals

  • Real Python — Defining Your Own Python Functions: realpython.com/defining-your-own-python-function
  • Theis, Thomas: Getting started with Python. 7. Edition, Rheinwerk Verlag, 2023 — Chapter on functions.
  • Klein, Bernd: Introduction to Python 3. 4. Edition, Hanser Verlag, 2021 — “Functions” section.