Coding· PythonHomeworkPredict, observe, explainRecall with feedbackBefore teachingAccessibility not checkedPublished

Truth in Python

By Alexis Diamond · Philosophy · Logic and argumentation · Undergraduate · Formal mathematics · version 4

Prototype for CS50: a Python version of the CS350 Lesson 3 workbook Truth in R. Students write OR, AND and NOT in Python, see how parentheses change the order Python works out a sentence, build the conditional from the connectives Python provides, then build truth tables with itertools.product and test De Morgan's law, asking what == over a whole table establishes that == at a single row cannot.

Licence: CC BY 4.0

Share and present
Assumption ledger (6)
  • simplificationSentences are atomic and two-valued: P, Q and S are each True or False.
  • interpretationPython's and, or and not stand for AND, OR and NOT; Python has no conditional operator, so P → Q is built as not P or Q. P <= Q gives the same values only through arithmetic on 0 and 1, and the page warns against it. Exclusive or is written P != Q or P ^ Q for True/False values: they are True exactly when exactly one of the two is True.
  • interpretationLogical equivalence is checked by comparing two expressions with == on every row of a truth table built with itertools.product; == at a single assignment shows agreement on that row only.
  • parameterCell 1 sets P = True, Q = False, S = True. With these values both expressions in cell 5 are False; the page has students set Q = True to see them differ, then rerun cell 1.
  • dataError messages quoted in questions 1 and 3 follow current CPython (3.10 and later) wording.
  • simplificationLeft out on purpose: short-circuit evaluation, truthiness of non-boolean values, the bitwise operators on numbers (^ is used only on True/False), operator.xor, and formal proof. A Python prototype for CS50 of the CS350 Truth in R workbook.
Checks Breakout ✓ · Code not checked · Accessibility ✓

Breakout check

✓ Ready for breakouts: every control we tried showed teammates the same thing.

Code checks

Not checked yet.

Cite this · History

Cite this

Alexis Diamond (2026). Truth in Python [Interactive model], version 4. Ideas at Play. https://ideasatplay.org/play/truth-in-python-47c62f?v=4 (CC BY 4.0)

History

  1. v4Homework-ready: lists every question (items) and keeps answers beside the page, released to homework copies only after the professor's answer date. (edited, Oct 31, 2026)current
  2. v3Fixed the exclusive-or wording (cell 9 and the P != Q feedback), added ^ as a correct option and in cell 9, updated two error messages to current CPython wording, wrapped cell 8's final test in print(), and made cell 7's example use a comprehension so p and q don't leak. (generated, Oct 31, 2026)View
  3. v2Refers to the CS350 Lesson 3 workbook (edited, Oct 31, 2026)View
  4. v1Imported; lineage before import is not available. (imported, Oct 31, 2026)View
Report this artifact

Reports are anonymous. The artifact stays up until we've checked it.

Comments

No comments yet.

Sign in to comment or like.

Anything wrong with this page? Submit feedback