Module · Detail
Functions with return (Calorie Check)
This module introduces functions with return value and connects string processing with numerical calculation. Learners structure a multi-step calculation process and implement it in Python in a way that is easy to follow.

Introduction (Original excerpt)
Didactic classification
Subjective objective
At its core is the implementation of a function with return value. Learners process structured text data, split it with split() and convert the individual components with float() to numerical values. Based on this, a given mathematical formula is modeled and correctly implemented.
Input analysis is required to structure a multi-step algorithm: analyze input, adjust data types, perform calculation, and provide result using return. The connection between model (calorie calculation formula) and implementation highlights the role of functions as self-contained, reusable computation units.
Competency development
- Implement a function with parameter and return value
- Break down a structured string using
split() - Convert character strings to numerical data types using
float() - Apply a given mathematical formula in code
- Structure a computation process into logically consecutive steps
- Further processing of a function return value in the main program
- Follow the separation of input, processing, and output of data
Didactic added value in teaching
- Clear focus on the concept “function with return value”
- Transparent decomposition of a problem into individual steps
- Systematic work with data types and conversions
- Linking mathematical models with algorithmic implementation
- Suitable building block for securing or deepening central concepts
Flow of the lesson unit
Calculate calories
A function is defined, which accepts a text parameter. The text is broken down into two components, converted to numbers, and processed according to the given formula. The result is returned and output in the main program. anzahl_kalorien defines a function that accepts a text parameter. The text is split into two components, converted to numbers and processed according to the given formula. The result is returned and displayed in the main program.
- Didactic focus: Structuring a calculation algorithm with return value
- Typical challenge: Correct data type conversion and order of calculation steps
Work assignment (excerpt)
- Define the function
anzahl_kalorienwith a parameter. - Split the given text with
split("/")into two values. - Convert both values with
floatto numbers. - Calculate kilocalories (amount × energy density ÷ 1000) and return the result with
return.
Example (excerpt)
| |
This excerpt illustrates the complete sequence of splitting, type conversion, calculation, and return within a clearly structured function.
Hints for classroom practice
- Suitable as a compact exercise phase (approx. 10 minutes) for introducing or securing functions with return values.
- Differenciation possible through additional test cases or alternative formulas.
- Result security through joint analysis of the function structure in the plenum.
- Expandable to error handling for incorrectly formatted inputs.
- Connects to topics such as data types, parameter passing, and modularization.
The clearly formulated task structure supports transparent lesson organization and facilitates targeted result verification. Differentiation is possible through further calculations or additional input formats.
Request a demo access and test the module in your own course context to systematically solidify functions with return values.