Chapter 4 · Course 4 c04-m04
How do you compare and convert?
Your goal Compare values using the right signs and convert numeric text only when you know what it represents.
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.
Story · optional context
The story so far
You are the new data hire at Aster Motors. Luca was injured in a crash involving a car resembling Noctis 01, and the prototype is missing. A log names your ID as the supposed author of a release. Mara Sol and independent investigator Imani examine authorized record copies. Two tables show the same count, but one stores it as text. Before reaching a conclusion, compare values of the same meaning and know when conversion is justified.
You can read this course alone. In Python, 4 is a number and '4' is text because of its quotes. Comparing numbers cannot by itself tell who performed an action.
Before the lesson
Purpose of this course
Compare values using the right signs and convert numeric text only when you know what it represents.
Topics covered
Read ==, !=, <, <=, >, and >=.; Understand that a comparison returns True or False.; Use int(), float(), and str() in simple examples.; See that conversion changes a value in the program, not the source document or its reliability.
What you will learn
- Read
==,!=,<,<=,>, and>=. - Understand that a comparison returns
TrueorFalse. - Use
int(),float(), andstr()in simple examples. - See that conversion changes a value in the program, not the source document or its reliability.
PART 1 · THE LESSON
Understand step by step
Lesson · explanation
A comparison asks one precise question
To compare two values is to ask a question that can be checked: are they equal, or which is larger? Python answers with True or False. These special values are called booleans. They help make decisions, but do not tell a whole story. If 4 == 4 is True, all you know is that the two numbers are equal.
Imagine two stacks of cards with four cards in each. You can answer yes to are the amounts equal. That does not mean the stacks contain the same cards, come from independent people, or are reliable. A narrow question gives a narrow answer.
In Python, == asks whether values are equal and != whether they differ. 5 == 5 is True, whereas 5 != 5 is False. The single sign = has another job: expected = 5 assigns five to the name expected. It does not ask a question. Two signs keep storing a value separate from checking it.
In the mission, Voss shows four marks that resemble the number five. Begin with precise questions: do A and B have the same type, are their quantities equal after a justified conversion, and is C even a quantity? Do not turn equal numbers into proof of authorization or an accusation about the missing prototype.
Pause and think
What exactly does 5 == 5 prove, and what does it not prove?
See the explanation
It proves only that the two numbers compared are equal. It does not prove the records are independent or identify who acted.
Lesson · explanation
Six signs ask six kinds of questions
The common comparison signs are == for equal, != for different, < for smaller, <= for smaller or equal, > for greater, and >= for greater or equal. 3 < 5 is True because three is smaller than five. 5 <= 5 is also True because equal is included. Read each sign as words before guessing its result.
Draw a number line. Three comes before five, so 3 < 5 is true and 3 > 5 is false. Five is in exactly the same place as five, so 5 >= 5 and 5 <= 5 are true while 5 != 5 is false. Each sign expresses one short relation between two values.
To ask whether five received cards reach five expected cards, use 5 >= 5. The answer is True because equal counts reach the threshold. 5 > 5 would be False: five is not strictly greater than five. Mara's phrase at least as many calls for >=, not >.
Only compare quantities with a compatible meaning and unit. 5 >= 5 becomes useful when the first five really means received cards and the second means expected cards for the same case. Comparing five cards with five minutes may produce a numerical answer but not one relevant to the investigation.
Pause and think
Which sign asks at least five, and what is 5 >= 5?
See the explanation
>= means greater than or equal to. 5 >= 5 is True.
Lesson · explanation
Type tells you what kind of value Python holds
A value's type describes how Python treats it. 5 is an integer, called int. '5' is a string of characters, called str, because quotes surround it. The symbol on the screen looks like a five in both cases, but one value is a quantity for calculations and the other is text.
Think of a five-euro note and a label saying five euros. Both mention the same amount, but a label is not a banknote. Likewise, '5' == 5 gives False in Python. That does not mean a document is lying. It means a direct comparison mixes two different types.
The function type() lets you inspect the difference: type('5') reports str, while type(5) reports int. In this first exercise, you can also look for the quotes. Later, CSV files, forms, and databases may provide numbers as text. Understand each field before converting it.
In the case file, A contains '5' for cards received, while B contains 5 for cards expected. The first technical question is '5' == 5, which gives False. Next check what field A means. If it truly counts cards and the text is a clear digit, you may consider converting it.
Pause and think
Why does '5' == 5 give False although both look like five?
See the explanation
'5' is text of type str; 5 is an integer of type int. Python treats them as different in a direct comparison.
Lesson · explanation
Convert a count without changing the evidence
The function int() tries to make an integer. int('5') gives the number 5, so int('5') == 5 is True. This makes a quantity comparison possible when the text really describes a whole count. float('1.5') gives decimal 1.5. str(5) makes the text '5' for display.
Imagine copying a quantity from a paper card into a calculator. You now have a number you can use, but the original card stays as it was. If it was stained or altered, the calculator does not repair it. Conversion creates a new working value; it does not prove the original text was correct or its writer honest.
For A, the cards received field has been confirmed and contains exactly '5'. Keep that raw spelling in your note, then make a numeric working value with int('5'). You may compare it with five expected cards. Tell readers that you converted A and why, so they can follow the same path.
Conversion can fail. int('5?') cannot make an integer because the question mark is not a confirmed digit. Do not remove it at random to obtain a preferred answer. Keep '5?', mark the note uncertain, and ask to inspect its original or source.
Pause and think
After int('5'), has the original document automatically changed its text '5' into a number?
See the explanation
No. Conversion makes a working value in the program. It does not edit the original document.
Lesson · explanation
A code that looks like a number is still a code
Some text contains only digits without representing an amount. A door, badge, or case number identifies one thing. For an identifier, the order and leading zeros can matter. The mission's door code '005' does not mean five doors; it names a particular door. Text is an appropriate type for that role.
If you use int('005'), Python gives 5. The two leading zeros disappear from the new value. For a quantity that does not change the amount; for a code it can change which item you mean. Imagine lockers labelled 005 and 5 in different buildings. Confusing them could send the team to the wrong place.
Before converting, ask whether this field is a quantity you intend to count or calculate, and whether someone has confirmed that meaning. A, cards received, can qualify. C, the door code, does not. The note '5?' is still unclear; wait for better evidence.
Python can accept int('005') without error. That is the trap: a technically permitted operation can be wrong for the mission. Preserve the original spelling, its field name, its unit if any, and its source before calculating. These details protect the meaning of data.
Pause and think
Why is int('005') technically possible but unsuitable for this door code?
See the explanation
Python can make integer five, but this field is an identifier whose leading zeros belong to the spelling that must be kept.
Lesson · explanation
Equal counts are not complete evidence
After conversion, A and B can both equal five. That answers a limited question about their quantities. To understand the crash and the missing prototype, ask more: do the cards refer to the same date, vehicle, and stage? Is B a copy of A? Who recorded each value, and when?
Think of two pupils submitting the same answer to a problem. They may have solved it independently, or one may have copied the other. Equal answers alone cannot choose between those stories. Likewise, two Noctis 01 tables saying five are not automatically two independent pieces of evidence. Inspect their provenance.
Explain your result in three parts: A is text while B is an integer; after converting A because it counts cards, both quantities are five; the originals, dates, and possible copies still need checking. Mara and Imani can then distinguish what you observed, the operation you performed, and the investigation that remains open.
Voss wants A, B, door code C, and the uncertain '5?' to appear as four matching proofs. Show step by step why that is wrong, without declaring Voss guilty from this calculation alone. A careful data engineer prevents a rushed certainty, especially when a report might accuse someone.
Pause and think
If A and B both equal five after conversion, what two checks are still useful?
See the explanation
Check their dates and original documents, and whether B copies A. Equal counts alone do not prove independent sources.
PART 2 · WATCH IT WORK
A complete worked example
Follow each step, then the result
Worked example: two ways to write one count
Sheet A contains '4' in “cards received”; sheet B contains 4 for the same field and date. A is confirmed as a quantity, not an ID.
type('4')indicates text andtype(4)an integer. Direct'4' == 4isFalse.- Because A is truly a quantity made of digits,
int('4')makes integer4. int('4') == 4givesTrue. It only says the converted quantities are equal.- Check original sheets. If B copies A, this equality is not two independent pieces of evidence. Preserve A's raw
'4'.
Conversion can make a technical comparison possible; provenance determines what it proves.
How this helps with your missionThe worked example compares '4' and 4 directly, then after a justified conversion, while preserving the original cards. Repeat those steps with A ('5') and B (5): first False, then True using int('5'). Ask int('5') >= 5 to check the threshold. The same reasoning keeps door code C ('005') and uncertain note '5?' out of that calculation. It helps Imani answer Voss without inventing a culprit.
PART 3 · YOUR TURN
Use the lesson to solve the mission
Story scene · practical task
Mission: avoid a false match
Imani compares three Noctis 01 case notes. A has '5' for cards received; B has 5 for cards expected; C has door code '005'. A fourth hard-to-read note seems to say '5?'. Voss claims all four mean the same thing. Imani wants an answer a ten-year-old could check step by step.
Your task
- Compare A and B directly in Python, then after a justified conversion of A.
- Explain why C stays text and why
'5?'must not be forced into a number. - Write a question with
>=asking whether received cards reach the expected count. - Give a limited conclusion and name a source check.
How to know you have succeeded
- You predict
'5' == 5isFalseandint('5') == 5isTrue. - You keep
'005'as an ID and'5?'as doubtful text to check. - You write
int('5') >= 5and getTrueif A really counts cards. - You say equal counts prove neither authorization nor independent documents.
Try code or SQL and keep a local draft. The mission questions are checked separately below.
See the worked answer
- Direct
'5' == 5givesFalse. Since A is confirmed as a digit count,int('5') == 5givesTrue. - C is a door code whose leading zeros belong to the ID. Converting
'005'would lose that spelling.'5?'is uncertain; consult the original. int('5') >= 5givesTrue: five received reaches five expected if the counts are right.- Possible conclusion: “The counts both equal five after converting A, but we must check dates, units, originals, and duplicates. Door code and unreadable note do not confirm the count.”
You can compare without erasing meaning. Next, you will organize several receipts in lists and dictionaries.
Before you leave
Remember this
- A comparison asks one precise question and returns
TrueorFalse. =assigns a value;==compares.>=includes equality.'5'is text and5is an integer, so a direct comparison isFalse.- Convert numeric text only after confirming it represents a quantity, and keep the original.
- An identifier like
'005'and an uncertain note like'5?'must not be forced into counts. - Equal counts prove neither source reliability nor independence.
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.
- Comparison
- A question asked of two values, such as “are they equal?”
- ==
- Asks whether values are equal. It differs from
=, which assigns a value to a name. - !=
- Asks whether values are different.
- Conversion
- Making a value of another type from an existing value when that makes sense.
- int()
- Tries to make a whole number;
int('4')gives4. - float()
- Tries to make a decimal number;
float('1.5')gives1.5. - str()
- Makes text;
str(4)gives'4'.