Programming exercises on Boolean logic — develop each solution yourself and check it directly in the browser.
Part 1 — AND Truth Table
Generate all four input combinations with nested loops.
Exercise
Iterate through A and B using first False, then True. Print exactly one line per combination in the format 0 AND 1 = 0 . Convert the Boolean values using int() to 0 or 1.
Note Use two nested forloops and an f-string. Additional output causes the test to fail.
Part 1 — Your Code
Loading Python…Tests
Part 2 — Verify De Morgan
Compare both sides of the first De Morgan law.
Exercise
The first De Morgan law reads ¬(A ∧ B) = ¬A ∨ ¬B. Define a function de_morgan(a, b)that computes both sides of this law in Python and returns them as the tuple (linke_seite, rechte_seite) . Translate ¬ as not, ∧ as and and ∨ as or. The check calls your function with all four assignments.
Objective For every assignment both entries of the tuple must be equal — that is the proof of the law by truth table.
Part 2 — Your Code
Loading Python…Tests
Part 3 — Middle Segment of a Seven-Segment Display
Translate three input bits into segment control.
Exercise
Define segment_g(x2, x1, x0) for the binary-coded digits 0 to 7. The middle segment g is on for 2, 3, 4, 5, and 6; it is off for 0, 1, and 7. Return a Boolean value.
Note First write the truth table for all eight inputs on paper. Manually derive a DNF from the rows with result 1 or a CNF from the rows with result 0. Record your chosen normal form as a code comment and translate it using and, or and not directly into the return expression. Do not convert to decimal or use set membership. The tests check all eight input combinations and the form of the expression.
Part 3 — Your Code
Loading Python…Tests
Part 4 — Half Adder
Add two bits and return the sum and carry.
Exercise
Define halbaddierer(x, y). The function returns a tuple (summe, uebertrag) . Formulate the sum bit using only and, or and not; the carry is an AND operation.
Example For two set bits, (False, True) is expected.
Part 4 — Your Code
Loading Python…Tests
Part 5 — Safe System Enable
Combining safety conditions with one exception.
Exercise
A machine may only start if the safety door is closed and the emergency stop is not activated. Two-hand operation must also be active — except in maintenance mode, which replaces two-hand operation. It does not override the door or emergency stop. not_aus_aktiviert = True means the emergency stop is activated and the machine remains blocked, including in maintenance mode. Define anlage_freigeben(schutztuer_zu, not_aus_aktiviert, zwei_hand_aktiv, wartung=False) and return True if the machine may start.
Note First write the rule on paper as a logical expression with ∧ and ∨, then translate it. The check tests all sixteen assignments and the call without the fourth parameter.
Part 5 — Your Code
Loading Python…Tests
Report as PDF
Document and download your solutions.
Module overview
| Part | Status |
|---|---|
| Part 1: AND Table | Open |
| Part 2: De Morgan | Open |
| Part 3: Segment g | Open |
| Part 4: Half Adder | Open |
| Part 5: System Enable | Open |
Not all parts are complete yet — the report can still be created.
Download PDF
Enter your name. The PDF contains your code, completion status, and a QR code for verification.