← Complete program

Chapter 5 · Course 3 c05-m03

How do you decide what to do?

Your goal Choose an action from available information while keeping uncertainty visible.

The lesson, the vocabulary, the worked example and the mission are separate blocks. You can follow them in order or return to the one you need.

Video explanation

This English explanation has English subtitles. Its examples may use a separate practice dataset; use the data stated in the written mission for your answers.

01

Story · optional context

The story so far

You are the new data hire at Aster Motors. Noctis 01 vanished after a crash that hurt Luca. A log bears your ID but does not establish who authorized the release. Voss wants you suspended. Independent investigator Imani wants doubtful receipts flagged without having your program decide anyone's guilt. Mara Sol shows you conditional Python rules.

You can start without earlier courses. A receipt can be a dictionary such as {'action': 'release'}. A condition asks a true-or-false question. You can follow all examples on paper.

02

Before the lesson

Purpose of this course

Choose an action from available information while keeping uncertainty visible.

Topics covered

Read if, elif, and else as possible paths.; Understand the colon and indentation belonging to each path.; Combine questions with and, or, and not.; Use in to test presence of a key or value without confusing presence with proof.

What you will learn

  • Read if, elif, and else as possible paths.
  • Understand the colon and indentation belonging to each path.
  • Combine questions with and, or, and not.
  • Use in to test presence of a key or value without confusing presence with proof.

PART 1 · THE LESSON

Understand step by step

1

Lesson · explanation

A condition asks one precise question

A condition is a question Python answers True or False. If action = 'release', then action == 'release' is true. The two signs == ask for a comparison. A single = gives a value to a name instead. The computer does not decide on its own that a card is authentic. It compares information already present in the program.

Imagine a helper reading the label on a box. If it says 'release', they put the box on a special table. That rule sorts labels; it does not reveal who wrote them or whether they tell the truth. In the Noctis 01 case, Imani wants a technical sorting rule that does not blame a person just because one word appears.

You can follow the lesson on paper. Write a card's values, then answer each condition in order. A says action = 'release' and source_confirmed = False. The text comparison is true, but the source confirmation is false. A program can keep these two answers separate instead of calling the whole card simply 'safe' or 'suspicious'.

A condition tests only the rule you wrote. action == 'release' does not mean 'a guilty person moved the car'. It means 'the text in the action variable matches the text release'. Precise wording keeps a technical comparison from becoming a dangerous claim about a person.

Pause and think

If action = 'received', what does action == 'release' return? Does the answer prove the document is genuine?

See the explanation

It returns False. It compares only action text and says nothing about whether the document is genuine.

2

Lesson · explanation

if, elif, and else make three paths

Picture three drawers: 'release confirmed as a document', 'release to check', and 'other action'. A Python if / elif / else chain picks one path for one card. Python first tries the if question. If it is false, it tries elif. If neither matches, it takes else.

Our rule uses if action == 'release' and source_confirmed: for the first drawer. elif action == 'release': picks the second when the first was not chosen. else: covers other actions, such as B marked 'received'. Once a path is chosen, Python does not follow the later paths of that same chain for this card.

A colon : announces the instructions below a path. Spaces at the start of a line are called indentation. They show that print('release to check') belongs to the elif path. Like steps on a staircase, the spacing makes the structure visible. If you move a line under the wrong path, the program may show the wrong label.

Do more than memorize the words. Take card B with action = 'received'. Its if test fails, then its elif test fails. The program uses else and displays 'other action'. This does not mean B has no value; this particular rule focuses on release claims.

Pause and think

With action = 'received', which path runs and what appears?

See the explanation

Both release questions are false. else runs and displays other action.

3

Lesson · explanation

and needs two true answers

and means both questions must be true. For action == 'release' and source_confirmed, there must be a release label and a confirmed document source. Think of a door with two keys: one key alone will not open it. If either part is false, the whole condition is false.

For A, the action says 'release', but its source is unconfirmed. The answers are true and false, so if fails. The elif still recognizes the release label and displays 'release to check'. The rule keeps uncertainty visible. Lack of confirmation is not proof that the document is false.

For C, the action also says 'release' and the source document has been checked. Both answers are true. The first path displays 'release confirmed'. Here 'confirmed' describes the document under the stated check, not the identity of the person who created or used it. The human author is still unknown.

A name such as source_confirmed makes a promise to readers of the code. Set it to True only after a real check of the source. If Voss writes True without looking at the document, Python follows the first path neatly but produces a misleading label. A correct rule cannot repair a false input.

Pause and think

Why does A not enter 'release confirmed' even though it says 'release'?

See the explanation

Because source_confirmed is False; with and, both parts must be true.

4

Lesson · explanation

or allows either; not reverses an answer

or accepts at least one true question. action == 'received' or action == 'checked' accepts a card marked 'received' or 'checked'. With 'release', both comparisons are false. To read a longer question, answer its left part, answer its right part, and then combine the results.

For B, action = 'received'. The left part of that or is true and the right part false, so the whole question is true. However, the displayed sample program does not use this or condition. It sends B to 'other action'. Knowing how to write a condition does not change a program unless you add that condition to it.

not reverses a true-or-false answer. If source_confirmed is False, then not source_confirmed is True. If the source is confirmed, the result is False. This helps spot documents whose sources need checking. It does not prove their contents are false: 'not confirmed' and 'disproved' mean different things.

Watch for a counterexample. Writing source_confirmed = not source_confirmed would change the variable in your program. The mission does not ask you to turn a card into a confirmed one by force. It asks you to write the question not source_confirmed and see whether confirmation is missing.

Pause and think

For B marked received, what is action == 'received' or action == 'checked'? For unconfirmed A, what is not source_confirmed?

See the explanation

Both are True in their examples. B satisfies the left side of or; not False is True for A.

5

Lesson · explanation

in checks presence, not truth

A Python dictionary resembles a card with named fields. receipt = {'action': 'release', 'source': None} has a 'source' key. The question 'source' in receipt is True because that key exists. Yet its value is None, so no source is supplied here. A field's presence is different from the presence of evidence.

To inspect a field, receipt.get('source') reads what is under that key. The example gives None. Even if you found a file name there, you would still need to inspect the original and confirm it matches the card. A filled field could contain a mistaken copy or a false claim.

The same word in can search a list. 'R21' in ['R21', 'R22'] is true because R21 appears there. But putting 'R21' into a list does not authenticate the receipt. Python knows the characters you entered; it has not visited the warehouse to inspect signatures and dates.

In the mission, Voss would like to treat every card containing 'source' as confirmed. Reject that shortcut. You may say the field exists, then ask what its value is and where the information came from. A card should remain 'to check' until those questions have answers.

Pause and think

With receipt = {'source': None}, what is 'source' in receipt? Does it confirm the source?

See the explanation

It is True because the key exists. It does not confirm the source: the value is None and the original document still needs checking.

6

Lesson · explanation

Trace A, B, and C without naming a culprit

Make a three-row table. A: action = 'release', source_confirmed = False. B: action = 'received'; in the shown rule its confirmation does not change the path, because its action is not 'release'. C: action = 'release', source_confirmed = True after the document was checked. Do not mistake that check for identifying its author.

For A, the first test fails because of False; then elif succeeds: 'release to check'. For B, both release tests fail: 'other action'. For C, the first test succeeds: 'release confirmed' in the sense of the document source. Each card takes one path.

Imani can now plan her work: request A's original, keep B among other actions, and continue investigating who wrote C. The program makes the card statuses visible without saying your ID proves your action. A technically confirmed card still does not identify who was at the wheel or keyboard.

If you change the rule, trace each card again on paper before trusting the new output. Conditions are useful because they make reasoning repeatable. They remain limited by the information given to them. Keep the originals, note what is missing, and explain each label in a sentence Imani can check.

Pause and think

What are the results for A, B, and C? Which of them proves a person is guilty?

See the explanation

A: release to check; B: other action; C: release confirmed for the document. None proves a person's guilt.

Code · read each line

A careful rule, line by line

action = 'release'
source_confirmed = False
if action == 'release' and source_confirmed:
    print('release confirmed')
elif action == 'release':
    print('release to check')
else:
    print('other action')

Here source_confirmed is False. The first path fails; the second finds the release label and shows release to check. This says nothing about who was responsible.

PART 2 · WATCH IT WORK

A complete worked example

Follow each step, then the result

Worked example: a label without a source

A card has action = 'release'. Its original has not been obtained, so source_confirmed = False. Mara follows the rule above.

  1. Test action == 'release' and source_confirmed: the first half is true and the second false, so and makes it false.
  2. Try elif action == 'release': this is true.
  3. Show release to check. The else block is skipped.
  4. Keep the card in the human case file and request its source. Do not turn this label into blame against the new hire.
What this shows

A useful rule can spot a release claim while leaving its confirmation open.

How this helps with your mission

Mara's worked example follows a release label with an unconfirmed source: if fails, elif succeeds, and the card stays 'to check'. In the mission, follow the same path for A, then compare B and C without using Voss's 'guilty' label. or, not, and in explain the questions you ask, while original documents remain necessary to confirm the facts.

PART 3 · YOUR TURN

Use the lesson to solve the mission

Story scene · practical task

Mission: decide without erasing doubt

Imani must sort three cards before an internal hearing. A says “release” but its source is not confirmed. B says “received” with a warehouse card. C says “release” and its source has been checked as a document, but the human author is not yet known. Voss wants both A and C in a drawer marked “guilty.” Mara asks for a technical sorting rule describing card status only.

Your task

  1. Give A and C values for action and source_confirmed, then follow the sample if, elif, else.
  2. Explain B's path and write an or condition allowing “received” or “checked.”
  3. Write a not question for an unconfirmed source.
  4. Explain why a 'source' key on a card does not prove its value is true.

How to know you have succeeded

  • A goes to “release to check”; C to “release confirmed” as a document, without a verdict on the author.
  • B follows “other action”; you write a correct or condition.
  • You use not source_confirmed to spot unconfirmed sources.
  • You separate a field's existence from evidence of its accuracy.
Open this mission in the browser workspace

Try code or SQL and keep a local draft. The mission questions are checked separately below.

Check the facts in your mission

Answer each factual question, then write your report in your own words. The program checks the choices; compare the report with the worked answer below.

1. A says 'release' but its source is unconfirmed. Which path does the rule take?
2. C says 'release' and its source document was checked. What does the rule's output mean?
3. B says 'received'. What does the shown rule do, and which `or` question accepts 'received' or 'checked'?
4. Which question is true for A's unconfirmed source and false for C's confirmed source?
5. For `receipt = {'source': None}`, what does `'source' in receipt` establish?
See the worked answer
  1. A: action = 'release', source_confirmed = False; the second path shows release to check. C has the same action and True confirmation; the first path says release confirmed for the source, not for a person.
  2. B has action = 'received', so the shown rule takes else. Another question could be action == 'received' or action == 'checked'.
  3. not source_confirmed is true for A and false for C.
  4. 'source' in receipt checks only for a key. Its value may be None, a copy, or a false claim. Inspect the original.

You can choose a path for one card. Next, a loop will apply a rule across many receipts without double counting.

Before you leave

Remember this

  • A condition gives True or False for one precise question. == compares; = gives a value to a name.
  • In an if / elif / else chain, one branch runs. The colon and indentation show its block.
  • and needs both answers true; or needs at least one; not reverses an answer.
  • in checks whether a key or value is present in data, not whether its contents are genuine.
  • A needs checking, B is another action, and C has a confirmed release document without any verdict on its author.
A–Z

Part of the lesson · keep nearby

New words, explained

These are the names of ideas used in the lesson above. Return here whenever a word feels unfamiliar.

Condition
A question Python answers with True or False.
if
If this question is true, follow the block beneath it.
elif
Otherwise, try this other question.
else
If earlier paths were not followed, use this one.
Indentation
Spaces at the start of a line showing which block it belongs to.
and, or, not
Both, at least one, and the opposite, used with true-or-false answers.
in
Asks about presence, as in 'source' in receipt.