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 — The typical workflow

Function above, called in the main block, returned in a variable.

Requirements

In this module, constructs from previous learning units are used together: Functions (Definition with def and return), the idiom if __name__ == "__main__":, as well Conditions and Grinding. If you are missing something in a component, take another look in the respective module.

The recurring pattern

  1. Function top define: def name(parameter):, calculate in the body, at the end return ergebnis.
  2. In the block if __name__ == "__main__": Create inputs as variables.
  3. Call function and the Return in a variable save.
  4. First after the result with the function call print() output.

This pattern makes the code reusable and easy to test — the function doesn't "know" where its input comes from.

In most parts of the programming task, you read the entries in the main block input() (introduced in the Variables module) and output only the result — the check automatically feeds in the input and compares your output character by character. However, for two parts (welcome and login) it says function itself in the center: you don't read anything there, but define the function and call it with values you choose - the runner then checks the function directly. The examples here use fixed values so that the Run button runs them directly.

Example 1.1 — Define a function, call it in the main block

Loading Python…
Output

    

Module 2 — Conditions within a function

A function returns different values depending on the input.

Multiple return-Pfade

A function can have several return-Instructions included. It is up to them to decide which of these will be carried out if-branching. As soon as a return is executed, the function is finished.

def begruessung(alter):
    if alter < 18:
        return "Hallo Kind"
    else:
        return "Hallo Erwachsener"

Example 2.1 — Function with if/else and return

Loading Python…
Output

    

Module 3 — Loops inside a function

Build accumulator patterns and lists.

Accumulate a value (while)

As with those while-exercises: an auxiliary variable outside the loop, inside it is built up step by step. After You pass the result to the loop return back - not with print.

Example 3.1 — Sum in a function

Loading Python…
Output

    

Build a list from a list (for)

The accumulator pattern also works for strings or lists. Create an empty list before the loop and use .append(...) Enter values and return the finished list.

Example 3.2 — even/odd via for + if

Loading Python…
Output

    

Module 4 — More than one return value

Functions can return multiple values at the same time.

Tuple-Return

Do you write in return If multiple values are separated by commas, Python returns them as Tuple back. In the main block you can distribute them directly to several variables - this is called Tuple-Unpacking.

def minmax(zahlen):
    return min(zahlen), max(zahlen)

kleinster, groesster = minmax([4, 7, 2, 9])

Example 4.1 — Tuple return and unpacking

Loading Python…
Output

    

TipOne function, many calls

The strength of features becomes apparent as soon as you use them multiple with different values. That's exactly what they're there for: define once, use as often as you like.

Example 4.2 — Call a function multiple times with different values

Loading Python…
Output

    

Sources & further literature

Where the knowledge imparted here is officially documented.

Official Python documentation

Tutorials & Manuals