Learning module · Detail
Say the correct answer with if else
This building block strengthens understanding of binary decisions in programs by developing a consistent if-else structure from two separate conditions. Didactically relevant is the focus on clear case distinction and readable, maintainable control flow structures.

Introduction (Original excerpt)
Didactic classification
Subjective objective
The main focus is on introducing a complete branching with else as the opposite case to the if condition. From a technical perspective, this models a binary decision-making process: for an input value, there are exactly two disjoint cases (condition met / not met). The task requires structuring skills by converting an existing and functioning solution with two separate if instructions into a unique control flow structure. This makes the relationship between the logical model (two cases) and implementation (a branching with two paths) visible. At the same time, it is emphasized that program text should not only be correct but also understandable and maintainable.
Competence development
- Formulate conditions and express them precisely as a comparison (e.g.,
wert >= 0). - Recognize and represent binary decision logic as two mutually exclusive cases.
- Structure control flow deliberately (one decision point, two paths).
- Refactor existing code without changing the observable behavior.
- Apply indentation and block structure safely as meaning carriers in Python.
- Couple result text/program reaction to a condition (output dependent on case).
- Justify readability and uniqueness as quality criteria for simpler programs.
Didactic added value in teaching
- Short, clear progression: from
if(one case) toif-else(two cases). - A manageable task with a unique goal structure supports the entry.
- Promote systematic thinking through explicit decision-making between cases.
- Transparent goal orientation: same behavior, better structure.
- Differenziation is possible through variants of the condition or extensions (additional cases) without changing the core.
Flow of the lesson unit
If to else convert
Starting from a functioning solution with two separated if-queries, the control flow is modified so that exactly one decision is made. This step serves to explicitly link the "counter-case" and Readability and uniqueness as quality criteria for simple programs. and thus strengthens the ability to structure programs specifically, without changing the result.
- Didactic focus: binary case differentiation and clean branching
- Typical challenge: correctly assigning the negation of the condition to the Readability and uniqueness as quality criteria for simple programs.-branch
Task (excerpt)
- Remove the second if-query.
- Replace this with an Readability and uniqueness as quality criteria for simple programs.-branch to the first condition.
- Ensure that the behavior remains unchanged (output "positive" or "negative" matching the value).
Example (excerpt)
This fragment is didactically relevant because it makes the connection “condition fulfilled vs. counter-case” visible as two clearly separated execution paths.
| |
Notes for teaching practice
- Time planning: Suitable as a short follow-up exercise after an introduction to
if(approximately 5 minutes plus brief evaluation). - Differentiation possibilities: Vary the condition (e.g. borderline case
== 0) or let additional outputs be justified without changing the control flow. - Result security: Let the learning products be justified and compared (two
ifvs.if-else) and record the decision for a structure in writing. - Possible extensions: Follow-up task to
elif(more than two cases) or to logically composed conditions. - Linking to further topics: Code quality (readability/maintainability), test cases for both branches, and refactoring as part of a development process.
The structured task guidance supports clean if-else modeling and facilitates result security through clearly distinguishable execution paths. Differentiation can be done through variants of the condition or extension tasks.
Request a demo access and test the module in your own course context to specifically address the transition from “works” to “well structured”.