Although computers are good at dealing with all kinds of information, two very important values are the values true and false.
These are the values returned by a computer when you ask it a question about information it is processing.
What types of questions can you ask it? How about questions that involve asking how two numbers compare. For example, is this
question 3 < 10 true or false? What about 56 >= 56? 9 == 9?
For this lesson, you'll use the
comparison operators, such as > (greater than) < (less than), <= (less than or equal), and/or
>= (greater than or equal). There is also == which means "check if equal." The single = sign is not used
for comparison, since it's used for assigning values to variables, as shown in this lesson.
In math, these operators are written as $<$, $>$, $\le$, $\ge$, and $==$. These are all called "comparison operators," since
they compare numbers. The results of such comparisons is either true or false. Let's see how they work.
< > <= >= == ~=
Move the mouse over a dotted box for more information.
In this lesson, use the print statement to display the result of these operators. Try these:
print(1 < 5) print(1 > 50) print(10 == 10) print(9 == 15) print(102 <= 102) print(3.27 >= 3) print(5 ~= 3)
Now you try. Using print, try displaying some true or false results, using these operators and some of your own numbers, that make logical sense to you.
Type your code here:
See your results here:
Show a friend, family member, or teacher what you've done!
Here is a share link to your code:
Does your code work? Want to run it on your iPhone?
Here's your code:
Use [Control]-[C] (Windows) or [⌘]-[C] (MacOS) to copy your code.
Paste it using [Control]-[V] (Windows) or [⌘]-[V] (MacOS) into
Then click the "Use on iPhone" button that you'll see.