Quarry School

Ask a true-or-false question

Subject: Computing
Level 1 · FoundationsAbout 7 min read3 new terms
How this was estimated

Programmatic estimate. Rung levels, worked steps, prerequisites, terms and sentence length contribute to this level. It describes the lesson, not your ability.

Reading counts the whole lesson, including folded explanations, at 180 words a minute. Practice allows two minutes per item. These are planning assumptions; take the time you need.

AI estimate unavailable.

Path to here

Open the unit’s lesson list to follow the lesson order.

    Leans on

    Quick review (2 minutes)

    In plain words

    A fairground ride has a height bar at its gate.

    Rule

    A comparison has a value on each side of a comparison operator. When both sides are numbers, or both are strings, Python works out the two sides, asks the question and gives back True or False. <, <=, > and >= ask about order. == asks whether the two values are equal, and != asks whether they differ.

    Two whole numbers are equal when they are the same number. Two strings are equal when they hold the same characters in the same order, so "Gate" == "gate" is False. A string and a whole number are never equal, so "6" == 6 is False. Asking about order between a string and a number, as in "6" < 7, stops the program with a TypeError.

    Step

    1. Say the question in words. For the boat program below, one question is whether the number of riders is more than the number of seats.

    2. Choose the operator that matches the words. "More than" is >. "At least" is >=. "Fewer than" is <. "At most" is <=. "Exactly" is ==. "Anything but" is !=.

    3. Check the types. A string and a whole number are never equal, so compare a number with a number and text with text. A value that came from input() is text. When that text is a whole number such as 6, int makes a number from it, as the second worked example shows.

    4. Work out each side to one value. Do any arithmetic first.

    5. Ask the question about those two values and write True or False.

    Trap

    The usual slip is typing = where you mean ==. In the Shell, riders = 6 gives the name a value and shows nothing. riders == 6 asks the question and shows True or False. When a comparison shows nothing, count the equals signs.

    A quieter slip is comparing text with a number. "6" == 6 is False, and Python raises no error to warn you. If the value came from input() and holds a whole number, make a number from it with int before you compare it with a number.

    The two-character operators have one spelling each. Write >=, <= and != with the = second. => and =< are not Python operators. A file that holds one stops with a SyntaxError before its first line runs.

    1 In plain words

    A fairground ride has a height bar at its gate. A rider either reaches the bar or does not. The attendant never writes down how tall anyone is. The bar gives one of two answers, yes or no.

    Python can ask the same kind of question about two values. Read 7 > 5 aloud as "is 7 greater than 5?" Python works the question out and gives back one of two values, True or False. These are the Boolean values, and their type is called bool. Write them with a capital first letter and no quotation marks.

    An expression that asks such a question is a comparison. The symbol between its two sides is a comparison operator. This lesson uses six: < for less than, <= for less than or equal to, > for greater than, >= for greater than or equal to, == for equal to and != for not equal to.

    A comparison of two numbers or two strings works out an answer and gives no name a new value. After riders > seats, both names hold what they held before. Giving a name a value is the job of an assignment, written with one =.

    This lesson leans on two tools from the first unit. input() reads a line the user types and hands it back as text. int makes a whole number from text such as "6". A leading zero does not change the number: from "04" it makes 4, as the badge example in the first unit showed.

    Remember one sentence: one = gives a name a value, and ==, written with two equals signs, asks whether two values are equal. To look the operators up, find the Comparisons section in the Built-in Types chapter of the Python 3.13 library reference.

    2 Picture it

    QuestionAnswer7 > 5True7 < 5False7 == 7True7 != 7False

    A table of four comparisons and their answers. 7 > 5 gives True. 7 < 5 gives False. 7 == 7 gives True. 7 != 7 gives False. The two rows that give True are marked.

    Each comparison works out to True or False

    3 Why

    Python treats a comparison as a calculation. 7 + 5 works out to the number 12. 7 > 5 works out to the value True. The answer is a value like any other, so a program can print it or give it a name.

    Arithmetic comes first. In riders == seats + 2, Python adds before it compares, so the question is asked about two finished values.

    The single = already has a job, which is giving a name a value. The question of whether two values are equal has its own spelling, ==, and != asks the opposite question. For the whole numbers and strings in this lesson, != gives True exactly when == gives False.

    4 The rule

    A comparison has a value on each side of a comparison operator.

    When both sides are numbers, or both are strings, Python works out the two sides, asks the question and gives back True or False. <, <=, > and >= ask about order. == asks whether the two values are equal, and != asks whether they differ.

    Two whole numbers are equal when they are the same number. Two strings are equal when they hold the same characters in the same order, so "Gate" == "gate" is False. A string and a whole number are never equal, so "6" == 6 is False. Asking about order between a string and a number, as in "6" < 7, stops the program with a TypeError.

    5 How

    1. Say the question in words. For the boat program below, one question is whether the number of riders is more than the number of seats.
    2. Choose the operator that matches the words. "More than" is >. "At least" is >=. "Fewer than" is <. "At most" is <=. "Exactly" is ==. "Anything but" is !=.
    3. Check the types. A string and a whole number are never equal, so compare a number with a number and text with text. A value that came from input() is text. When that text is a whole number such as 6, int makes a number from it, as the second worked example shows.
    4. Work out each side to one value. Do any arithmetic first.
    5. Ask the question about those two values and write True or False.

    6 Worked example

    Ask three questions about a boat

    Python code
    seats = 4
    riders = 6
    print(riders > seats)
    print(riders == seats + 2)
    print(riders != 6)
    

    Standard input

    Empty

    Standard output

    True
    True
    False
    

    Predict each of the three output lines first. Then save the five lines as boat.py and run the file, or follow the trace below. Each comparison works out to True or False, and the addition in the fourth line is done before its comparison.

    Compare a typed reply

    Python code
    reply = input()
    print(reply == 6)
    print(int(reply) == 6)
    

    Standard input

    6
    

    Standard output

    False
    True
    

    Save the three lines as reply.py, run the file, type 6 and press Enter. The first comparison sets the text "6" against the number 6, and a string never equals a whole number. The second makes a number from the reply first, so two numbers are compared.

    Trace

    Trace the three questions about the boat
    InstructionQuestion in wordsResultExplanation
    seats = 4——One = asks nothing. The name seats now holds 4.
    riders = 6——The name riders now holds 6.
    print(riders > seats)Is 6 greater than 4?TrueSix is greater than four, so Python displays True.
    print(riders == seats + 2)Is 6 equal to 4 + 2?TrueAdd first: 4 + 2 is 6. Then ask whether 6 equals 6.
    print(riders != 6)Is 6 different from 6?FalseSix is not different from six, so Python displays False.

    7 The trap

    The usual slip is typing = where you mean ==. In the Shell, riders = 6 gives the name a value and shows nothing. riders == 6 asks the question and shows True or False. When a comparison shows nothing, count the equals signs.

    A quieter slip is comparing text with a number. "6" == 6 is False, and Python raises no error to warn you. If the value came from input() and holds a whole number, make a number from it with int before you compare it with a number.

    The two-character operators have one spelling each. Write >=, <= and != with the = second. => and =< are not Python operators. A file that holds one stops with a SyntaxError before its first line runs.

    Quick checks

    Quick check 1 of 2

    Predict the three lines this program displays. The program reads no input.

    Python code
    tickets = 12
    group = 5
    print(tickets >= group * 2)
    print(tickets - 2 == group * 2)
    print(tickets != 12)
    Show the steps and the answer
    Answer

    It displays True, then True, then False, each on its own line.

    Why: Arithmetic comes first. 5 * 2 is 10, and 12 is at least 10. 12 - 2 is 10, which equals 10. The last line asks whether 12 differs from 12, and it does not.

    Source: Python Software Foundation, Python 3.13 Language Reference, 6.10 Comparisons

    Quick check 2 of 2

    A program runs code = input() and the user types 08. Which of these three comparisons give True?

    Python code
    code == 8
    code == "08"
    int(code) == 8
    Show the steps and the answer
    Answer

    code == "08" and int(code) == 8 give True. code == 8 gives False.

    Why: The reply is the text "08". Text equals text with the same characters, and text never equals a number. int turns "08" into the number 8, which equals 8.

    Source: Python Software Foundation, Python 3.13 Library Reference, Built-in Types: Comparisons

    Sources

    1. Python 3.13 Library Reference, Built-in Types: Boolean Type. Python Software Foundation. Python Software Foundation License Version 2. Read 1 Dec 2026.
    2. Python 3.13 Library Reference, Built-in Types: Comparisons. Python Software Foundation. Python Software Foundation License Version 2. Read 1 Dec 2026.
    3. Python 3.13 Tutorial, 3.1.1 Numbers. Python Software Foundation. Python Software Foundation License Version 2. Read 1 Dec 2026.
    4. Python 3.13 Library Reference, Built-in Functions: input. Python Software Foundation. Python Software Foundation License Version 2. Read 1 Dec 2026.
    5. Python 3.13 Library Reference, Built-in Functions: int. Python Software Foundation. Python Software Foundation License Version 2. Read 1 Dec 2026.
    6. Python 3.13 Language Reference, 6.10 Comparisons. Python Software Foundation. Python Software Foundation License Version 2. Read 1 Dec 2026.
    7. Python 3.13 Tutorial, 8.1 Syntax Errors. Python Software Foundation. Python Software Foundation License Version 2. Read 1 Dec 2026.