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.

Time 5 minutes
Language Python 2 (CE)
Tasks 1
Preview image: Say the correct answer with if else

Introduction (Original excerpt)

In the last task, you worked with if-queries. With this, you could check whether a condition is true.

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

Didactic added value in teaching

Flow of the lesson unit

1

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)

  1. Remove the second if-query.
  2. Replace this with an Readability and uniqueness as quality criteria for simple programs.-branch to the first condition.
  3. 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.

1
2
3
4
if wert >= 0:
    sag("positiv")
else:
    sag("negativ")

Notes for teaching practice

This module connects binary case differentiation with step-by-step implementation and creates a clear foundation for traceable control flow decisions.

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”.