Core by Critic
ChaptersStreak: 0 days

Ultimate Core Python · Chapter 5

Comparisons, Logic and Truthiness

This lesson goes with Episode 5 of the Ultimate Core Python course on the Core by Critic channel on YouTube.

0 of 0 done

Programs make decisions all the time. Is the password correct? Has the student passed? Is the cart empty? Before you can write the if statements that make decisions → Chapter 11, you need a way to ask questions and get yes-or-no answers. That's what this chapter is about: comparisons, which ask questions, and logic, which combines the answers.

5.1 Asking a question: comparison operators

A comparison asks a question about two values and answers with a Boolean: True or False (the bool type from Chapter 2).

Operator Question Example Result
== equal to? 5 == 5 True
!= not equal to? 5 != 5 False
< less than? 3 < 8 True
> greater than? 3 > 8 False
<= less than or equal to? 8 <= 8 True
>= greater than or equal to? 3 >= 8 False
age = 19
print(age >= 18)
print(age == 21)
print(age != 21)

Output

True
False
True

A comparison is an expression, so its result is a value you can print, store in a variable, or combine with other values:

marks = 72
passed = marks >= 35
print(passed)
print(type(passed))

Output

True
<class 'bool'>

Read passed = marks >= 35 as "passed gets the answer to the question is marks at least 35?". Comparisons are done before assignment, because = has the lowest priority of all.

Two-character operators must be typed without a space and in the right order: >=, not > = or =>.

Practice 5.1

Predict the output

What does it print?

price = 40
print(price == 40)
print(price != 40)
print(price <= 39)

Put the lines in order

Put the lines in order so that the program prints the target.

The program in the right order prints:

Target

True False
  1. marks = 72
  2. passed = marks >= 35
  3. print(passed, marks >= 35)
  4. marks = 20

Fix the bug

This should print False, because the level is 7 and not 5. It prints 5. Fix the second line and keep level = 7.

The program prints the lines below. Your program must print exactly these lines.

Example run

False

5.2 Comparing numbers

Numbers are compared by value, whatever their type. An int and a float with the same value are equal:

print(1 == 1.0)
print(7 > 6.99)
print(-3 < -2)
print(True == 1)

Output

True
True
True
True

True == 1 is True because, as Chapter 2 hinted, a bool is a kind of integer, with True worth 1 (section 5.12 explains).

Never test floats with ==

Remember from Chapter 2 that floats are approximate. That makes == unreliable for them:

print(0.1 + 0.2 == 0.3)
print(0.1 + 0.2)

Output

False
0.30000000000000004

Mathematically the answer is True, but the float sum is a tiny bit more than 0.3, so == says no. The fix is to ask whether two floats are close enough: subtract them, take the size of the difference with abs, and check it's smaller than some tiny amount (called a tolerance):

print(abs((0.1 + 0.2) - 0.3) < 1e-9)

Output

True

1e-9 is 0.000000001: two floats that differ by less than that are treated as equal. The math module has a ready-made function for this, math.isclose, which picks a sensible tolerance for you → Chapter 17:

import math
print(math.isclose(0.1 + 0.2, 0.3))

Output

True

Practice 5.2

Multiple choice

What does this line print?

print(0.1 * 3 == 0.3)
Choose one answer

Fill in the blank

Fill in the comparison operator so that the line asks: is the difference smaller than the tolerance?

total = 0.1 + 0.2
print(abs(total - 0.3)  1e-9)

The finished program prints:

Target

True

Write code

Close enough. Store 0.1 * 3 in a variable named total. Print two lines: first the result of comparing total with 0.3 using ==, then the result of a tolerance test that asks whether total and 0.3 differ by less than 1e-9. Each line is True or False.

The program prints the lines below. Your program must print exactly these lines.

Example run

False
True

5.3 Comparing strings

== and != on strings check whether two strings contain exactly the same characters, in the same order. Capitals and spaces count:

print("Python" == "Python")
print("Python" == "python")
print("Python" == "Python ")

Output

True
False
False

< and > on strings compare in dictionary order (also called lexicographic order). Python compares the first characters; if they're the same, it moves on to the second characters, and so on, until it finds a difference:

print("apple" < "banana")     # 'a' comes before 'b'
print("apple" < "apricot")    # 'ap' same, then 'p' comes before 'r'
print("cat" < "catch")        # a prefix comes before the longer word

Output

True
True
True

Every character has a number

"Comes before" is decided by each character's Unicode code point, the number from Chapter 1. The built-in ord() shows it (you'll explore it in → Chapter 9):

print(ord("A"), ord("Z"))
print(ord("a"), ord("z"))
print(ord("0"), ord("9"))

Output

65 90
97 122
48 57

Digits come before capital letters, which come before lowercase letters. That leads to two surprises:

print("Zebra" < "apple")
print("10" < "9")

Output

True
True

"Zebra" comes before "apple" because Z (90) is less than a (97): every capital comes before every lowercase letter. And "10" comes before "9" because, as text, Python compares the first characters, "1" and "9", and never looks at the rest. When numbers are stored as text, they don't sort like numbers. Convert them to real numbers first → Chapter 6.

Practice 5.3

Predict the output

What does it print?

print("cat" == "Cat")
print("pear" < "plum")
print("Zoo" < "bee")
print("100" < "25")

5.4 Comparing different types

== and != work between any two values. Values of unrelated types are simply never equal:

print(5 == "5")
print(5 != "5")
print(None == 0)

Output

False
True
False

5 is a number and "5" is text, so they're not equal. No error, just False. This is a common source of bugs when a number arrives as text (for example from user input), because the comparison quietly fails → Chapter 6.

Ordering comparisons (<, >, <=, >=) between unrelated types make no sense, so they're an error:

print(10 < "20")

Output

Traceback (most recent call last):
  File "compare.py", line 1, in <module>
    print(10 < "20")
          ^^^^^^^^^
TypeError: '<' not supported between instances of 'int' and 'str'

Is the number 10 less than the text "20"? There's no sensible answer, so Python refuses.

Practice 5.4

Multiple choice

Three of these lines run. Which one stops with a TypeError?

Choose one answer

5.5 Chained comparisons

In maths you write 0 ≤ marks ≤ 100 to say "marks is between 0 and 100". Python lets you write exactly that:

marks = 72
print(0 <= marks <= 100)
marks = 105
print(0 <= marks <= 100)

Output

True
False

This is called a chained comparison. Python treats a < b < c as a < b and b < c: both comparisons must be true. (and is explained in the next section.) The middle value b is worked out only once. You can chain as many as you like:

print(1 < 2 < 3 < 4 < 5)
print(1 < 2 > 3)

Output

True
False

The second line means 1 < 2 and 2 > 3. It's legal, but it reads strangely; keep chains to the "between" pattern.

Practice 5.5

Fill in the blank

Fill in both blanks so that the line asks: is speed between 30 and 80?

speed = 60
print(30  speed  80)

The finished program prints:

Target

True

Fix the bug

This should print True, because the score is more than 50. It prints False. Fix the second line and keep score = 80.

The program prints the lines below. Your program must print exactly these lines.

Example run

True

5.6 Combining answers: and, or, not

Real questions often have several parts. Can this person vote? They must be 18 or older and be a citizen. Is it the weekend? It's Saturday or Sunday. Python's logical operators combine Booleans in exactly this way:

Operator Result is True when... Example
a and b both a and b are true age >= 18 and is_citizen
a or b at least one of them is true day == "Sat" or day == "Sun"
not a a is false (it flips the answer) not is_logged_in
age = 20
is_citizen = True
print(age >= 18 and is_citizen)

day = "Sun"
print(day == "Sat" or day == "Sun")

is_logged_in = False
print(not is_logged_in)

Output

True
True
True

Truth tables

A truth table lists every possible combination of inputs and the result. These three tables define the operators completely:

a b a and b a or b
True True True True
True False False True
False True False True
False False False False
a not a
True False
False True

In words: and is only true if everything is true. or is only false if everything is false.

or in Python is inclusive: True or True is True. (In everyday English, "tea or coffee?" often means one but not both. That "one but not both" idea is called exclusive or, or XOR; one of the practice problems builds it.)

Precedence of the logical operators

When an expression mixes them, not is done first, then and, then or. All three are lower than comparisons, which are lower than arithmetic (look back at the table in Chapter 4). So this needs no brackets:

marks = 72
attendance = 80
print(marks >= 35 and attendance >= 75)

Output

True

Python works out both comparisons first, then the and. But mixing and with or can surprise you:

print(True or False and False)
print((True or False) and False)

Output

True
False

Because and is done before or, the first line means True or (False and False). When you mix and and or, always add brackets to show what you mean.

Similarly, not is lower than ==, so not a == b means not (a == b). That's usually what you want, but a != b says the same thing more clearly.

Negating a condition: De Morgan's laws

Sometimes you need the opposite of a combined condition. "Not (A and B)" is not "(not A) and (not B)". Two rules, called De Morgan's laws, tell you how to flip them correctly:

not (a and b)   is the same as   (not a) or (not b)
not (a or b)    is the same as   (not a) and (not b)

When you push a not inside the brackets, and turns into or, and or turns into and. For example, "marks is not between 0 and 100" is:

marks = 105
print(not (0 <= marks <= 100))
print(marks < 0 or marks > 100)

Output

True
True

Both lines ask the same question. The second is usually easier to read.

Practice 5.6

Put the lines in order

Put the lines in order so that the program prints the target.

The program in the right order prints:

Target

True False
  1. day = "Sat"
  2. weekend = day == "Sat" or day == "Sun"
  3. print(weekend, busy)
  4. busy = not weekend

Predict the output

What does it print?

print(False and False or True)
print(False and (False or True))
print(not True or True)

Fill in the blank

Both lines must ask the same question: is marks outside the range 0 to 100? Fill in the logical operator.

marks = 105
print(not (0 <= marks <= 100))
print(marks < 0  marks > 100)

The finished program prints:

Target

True
True

Write code

Free delivery. Delivery is free when the total is at least 50 dollars, or when the customer is a member. Store the total in total and the membership in member (True or False). Print one line, True or False, for each of these three customers, in this order: total 45 and not a member, total 45 and a member, total 60 and not a member.

The program prints the lines below. Your program must print exactly these lines.

Example run

False
True
True

5.7 Short-circuit evaluation

Look at the truth tables again. If the left side of and is False, the answer is False whatever the right side is. If the left side of or is True, the answer is True whatever the right side is. Python takes advantage of this: it doesn't even look at the right side when the left side already decides the answer. This is called short-circuit evaluation.

You can prove it. Dividing by zero is an error, but here it's never done:

print(False and 1 / 0)
print(True or 1 / 0)

Output

False
True

In both lines, Python stopped after the left side, so 1 / 0 never ran.

This isn't just a curiosity. It lets you put a guard on the left that protects the right:

count = 0
total = 50
print(count != 0 and total / count > 10)

Output

False

If count is 0, the left side is False, so Python never reaches the division that would crash. If count isn't zero, the division is safe. Put the cheap, protective check first, and the risky or expensive one second.

Practice 5.7

Multiple choice

What does this program print?

count = 0
print(count != 0 and 10 / count > 2)
Choose one answer

Fix the bug

This should print False when there are no matches. It crashes with a ZeroDivisionError. Fix the last line and keep the two values.

The program prints the lines below. Your program must print exactly these lines.

Example run

False

5.8 Truthiness

So far, and, or and not have worked on True and False. But Python lets you use any value where a true-or-false answer is needed. Every value counts as either true or false; programmers say it's truthy or falsy.

The rule is simple: these values are falsy, and everything else is truthy.

Falsy values
False the Boolean
None no value
0, 0.0, 0j zero, of any number type
"" the empty string
[], (), {}, set(), range(0) empty collections → Chapter 25

In short: zero, empty and nothing are false. The built-in bool() shows how any value counts:

print(bool(0), bool(0.0), bool(""), bool(None))
print(bool(42), bool(-1), bool(0.001), bool("hi"))

Output

False False False False
True True True True

A few values look false but are truthy:

print(bool("False"))
print(bool("0"))
print(bool(" "))

Output

True
True
True

"False" and "0" are non-empty strings, so they're truthy; Python doesn't read the text inside them. " " (a single space) isn't empty either: it contains one character.

Truthiness makes conditions short and natural. Instead of asking "is the name not equal to the empty string?", you can just ask "is there a name?" You'll use this all the time with if → Chapter 11 and while → Chapter 13.

Practice 5.8

Predict the output

What does it print?

print(bool("no"), bool(""), bool(-5))
print(bool(None), bool("0"), bool(0.0))

Multiple choice

Three of these values are truthy. Which one is falsy?

Choose one answer

5.9 What and and or really give back

Here's something most beginners don't know. and and or don't always give back True or False. They give back one of their operands: the one that decided the answer.

  • a or b: if a is truthy, the answer is a (no need to look further). Otherwise it's b.
  • a and b: if a is falsy, the answer is a. Otherwise it's b.
print(3 or 5)
print(0 or 5)
print(3 and 5)
print(0 and 5)

Output

3
5
5
0

Walk through them: 3 or 5 → 3 is truthy, so the answer is 3. 0 or 5 → 0 is falsy, so the answer depends on 5, and that's what you get. 3 and 5 → 3 is truthy, so 5 decides. 0 and 5 → 0 is falsy, so it's the answer straight away.

With real Booleans, this gives exactly the truth tables from section 5.6, so you've been using it all along. With other values, it gives a very handy idiom for default values:

name = ""
print(name or "Guest")

name = "Alex"
print(name or "Guest")

Output

Guest
Alex

"Use name, or if it's empty, use "Guest"." You'll see value or default all over real Python code.

not is different: it always gives back a real bool:

print(not 0)
print(not "hello")

Output

True
False

Watching short-circuiting happen

Remember from Chapter 2 that print gives back None, which is falsy. That lets you see exactly which parts of an or actually run:

print(print("left") or print("right"))

Output

left
right
None

The left print runs, shows left and gives back None. That's falsy, so or must look at the right side: right is shown, and its None becomes the answer, which the outer print displays. Now change or to and:

print(print("left") and print("right"))

Output

left
None

The left side gave back None, which is falsy, so and stops. right is never printed.

Practice 5.9

Predict the output

What does it print?

print(7 or 0)
print(0 and 7)
print("" or "none given")
print(not 7)

Fill in the blank

Fill in the operator so that the program prints the name, or Guest when the name is empty.

name = ""
print(name  "Guest")

The finished program prints:

Target

Guest

Write code

Default city. Store the empty string in a variable named city. Print city, or the text Unknown when city is empty, using one expression and no bool(). Then store "Lima" in city and print with the same expression again. The program prints two lines.

The program prints the lines below. Your program must print exactly these lines.

Example run

Unknown
Lima

5.10 A very common bug

Here's a mistake almost every beginner makes. We want to check whether day is a weekend day:

day = "Mon"
print(day == "Sat" or "Sun")

Output

Sun

We expected False, but got Sun! In English, "day is Saturday or Sunday" makes sense. But Python reads it as (day == "Sat") or ("Sun"). The left part is False, so or gives back the right part, the string "Sun", which is truthy. Used in an if, this "condition" would always be true, whatever the day.

Each side of or must be a complete question:

day = "Mon"
print(day == "Sat" or day == "Sun")

Output

False

(There's an even neater way to write this using in and a collection of days: day in ("Sat", "Sun") → Chapter 30.)

Practice 5.10

Multiple choice

What does this program print?

drink = "tea"
print(drink == "milk" or "juice")
Choose one answer

5.11 Identity: is and is not

== asks whether two values are equal. is asks a different question: are these the same object in memory? Remember the label picture from Chapter 3: two names can be tied to one object, or to two separate objects that happen to look the same.

Lists show the difference clearly. A list is a collection of values in square brackets → Chapter 25:

a = [1, 2, 3]
b = [1, 2, 3]
c = a
print(a == b)
print(a is b)
print(a is c)

Output

True
False
True

a and b are two different lists with the same contents: equal, but not the same object. c = a ties a second label to the very same list as a, so a is c is True. x is y is the same question as id(x) == id(y) from Chapter 3. is not is the opposite: a is not b is True here.

When to use is

Use is for exactly one common job: checking for None.

result = None
print(result is None)
print(result is not None)

Output

True
False

There's only ever one None object, so is None is the precise and recommended way to ask "is there no value?". PEP 8 says to always write x is None, never x == None.

For everything else, especially numbers and strings, use ==. Whether two equal numbers or strings are the same object depends on internal speed tricks (like the small-integer cache from Chapter 3), which can change between Python versions. Python even warns you if you write x is 5:

SyntaxWarning: "is" with 'int' literal. Did you mean "=="?

Practice 5.11

Multiple choice

Which line is the recommended way to ask whether result has no value?

Choose one answer

Predict the output

What does it print?

result = None
print(result is None)
print(result is not None)
print(result == 0)

5.12 Membership: in and not in

in asks: is this value inside that one? With strings, it checks whether one piece of text appears anywhere inside another:

print("py" in "python")
print("Py" in "python")
print("z" not in "python")

Output

True
False
True

Like ==, it's case-sensitive: "Py" isn't in "python". in really comes into its own with collections — is this student in the list? is this word in the dictionary? → Chapter 25.

Here's the complete set of comparison operators. They all have the same precedence and can all be chained:

Kind Operators
Value comparisons == != < <= > >=
Identity is, is not
Membership in, not in

Practice 5.12

Fill in the blank

Fill in the membership operators so that both lines print True.

word = "notebook"
print("book"  word)
print("pen"  word)

The finished program prints:

Target

True
True

Put the lines in order

Put the lines in order so that the program runs and prints the target.

The program in the right order prints:

Target

True False
  1. print(found, "Th" in word)
  2. found = "th" in word
  3. word = "python"

5.13 How Python does logic

Practice 5.13

Write code

Count the true ones. Store the result of each of these three comparisons in its own variable: is 7 greater than 3, is "b" inside "bus", is 0.5 greater than 1. Then print one line: how many of the three are true, found by adding the three variables.

The program prints the lines below. Your labels can be different. The numbers must be the same, in the same order.

Example run

2

+ Practice

Questions with a Check button are checked on this page. Use the hints when you are stuck: the last step always shows the answer. The other questions show the book's answer, so that you can compare.

Questions

Check yourself

What's the difference between x = 5 and x == 5?

Show the answer

x = 5 assigns: it makes x refer to 5. x == 5 compares: it asks whether x equals 5 and gives True or False.

Check yourself

Why does 0.1 + 0.2 == 0.3 give False? Write a comparison that correctly checks whether they're equal.

Show the answer

Floats are stored in binary and are slightly off, so the sum is 0.30000000000000004. Use abs((0.1 + 0.2) - 0.3) < 1e-9 or math.isclose(0.1 + 0.2, 0.3).

Check yourself

Why is "Zebra" < "apple" true? Why is "10" < "9" true?

Show the answer

Strings compare by code point, and every capital letter (Z is 90) comes before every lowercase letter (a is 97). As text, "10" and "9" are compared by their first characters, and "1" comes before "9".

Check yourself

What does 5 == "5" give? What does 5 < "5" give?

Show the answer

False: a number and a string are never equal. 5 < "5" is a TypeError, because Python can't order an int and a string.

Check yourself

Rewrite x >= 10 and x <= 20 as a chained comparison.

Show the answer

10 <= x <= 20.

Check yourself

Using De Morgan's laws, rewrite not (is_raining or is_cold) without brackets around an or.

Show the answer

not is_raining and not is_cold.

Check yourself

Explain what short-circuit evaluation is, and why count != 0 and total / count > 5 never divides by zero.

Show the answer

Python stops evaluating and as soon as the answer is known. If count != 0 is False, the whole and must be False, so the division on the right is never run.

Check yourself

List six falsy values. Is "0" truthy or falsy? Why?

Show the answer

False, None, 0, 0.0, "", [] (also 0j, (), {}, set()). "0" is truthy: it's a non-empty string, and Python doesn't look at what the text says.

Check yourself

What does "" or "default" give? What does "hello" and 0 give?

Show the answer

"default", because "" is falsy. 0, because "hello" is truthy, so and gives back the right side.

Check yourself

Why should you write x is None but x == 5?

Show the answer

There's only one None object, so identity is exactly the right test. Equal numbers may or may not be the same object, depending on internal details, so numbers must be compared by value with ==.

Predict the output

Predict the output

print(10 >= 10, 10 > 10, 10 != 10.0)
print("cat" < "dog", "Cat" < "cat", "b" > "abc")

Predict the output

x = 15
print(10 < x < 20)
print(x > 10 and x % 2 == 0)
print(not x > 10 or x == 15)

Predict the output

print(0 or "zero")
print("" and "empty")
print(None or 0 or "last")
print(1 and 2 and 3)

Predict the output

print(bool(" "), bool(0.0), bool("None"), bool(None))
print(True + True == 2)

Fix the bug

Fix the bug

This should print True when the colour is red or green. With colour = "blue", it prints green.

Keep colour = "blue" on the first line.

The program prints the lines below. Your program must print exactly these lines.

Example run

False

Fix the bug

This should print True, because the total is 0.3.

The program prints the lines below. Your program must print exactly these lines.

Example run

True

Fix the bug

This should print whether score_a (stored as text, "9") is a lower score than score_b ("10"). It prints False.

The program prints the lines below. Your program must print exactly these lines.

Example run

True

Fix the bug

This should print True only when the age is from 13 to 19 inclusive. It crashes.

Keep age = 16 on the first line.

The program prints the lines below. Your program must print exactly these lines.

Example run

True

Coding problems

Write code · Easy

Can they vote?. Store an age and whether the person is a citizen (True/False). Print True if they can vote: at least 18 and a citizen. Test with three different people.

Test these three people, in this order: 20 years old and a citizen, 16 years old and a citizen, 30 years old and not a citizen. Print one line for each person: True or False.

The program prints the lines below. Your program must print exactly these lines.

Example run

True
False
False

Write code · Easy

Pass or fail. A student passes if they score at least 35 in each of three subjects. Store three marks and print whether the student passed.

Use the marks 72, 34 and 81. Print one line: True or False.

The program prints the lines below. Your program must print exactly these lines.

Example run

False

Write code · Easy

Password check. Store a password and a confirm value. Print True only if they match and the password isn't empty. Use truthiness for the "not empty" part. (Checking for a minimum length needs len() → Chapter 7.)

Test two cases, in this order: both values are "sunny123", then both values are the empty string. Print one line for each case, and wrap the expression in bool() so that each line is True or False.

The program prints the lines below. Your program must print exactly these lines.

Example run

True
False

Write code · Medium

Leap years. A year is a leap year if it's divisible by 4 but not by 100, or it's divisible by 400. Print whether each of 1900, 2000, 2024 and 2026 is a leap year, using one Boolean expression.

Print four lines, in the order 1900, 2000, 2024, 2026. Each line has the year, one space, then True or False.

The program prints the lines below. Your program must print exactly these lines.

Example run

1900 False
2000 True
2024 True
2026 False

Write code · Medium

Valid triangle. Three lengths can form a triangle only if each one is less than the sum of the other two. Store three sides and print whether they form a triangle. Test with 3, 4, 5 and with 1, 2, 10.

Test the sides 3, 4, 5 first, then 1, 2, 10. Print one line for each test: True or False.

The program prints the lines below. Your program must print exactly these lines.

Example run

True
False

Write code · Medium

Out of range. Print whether a temperature reading is outside the safe range of 2 °C to 8 °C (a vaccine fridge), in two ways: once with not and a chained comparison, and once using or without not.

Use the reading 9.5. Print two lines: first the version with not and a chained comparison, then the version with or.

The program prints the lines below. Your program must print exactly these lines.

Example run

True
True

Write code · Hard

Build XOR. Python has no logical XOR operator for Booleans. Write an expression using only and, or and not that's True when exactly one of a and b is True. Print its value for all four combinations of a and b. Then show that a != b gives the same answers.

Print four lines, for the combinations in this order: True True, True False, False True, False False. On each line print four values with one print and commas: the first Boolean, the second Boolean, your expression, then the result of comparing the two with !=.

The program prints the lines below. Your program must print exactly these lines.

Example run

True True False False
True False True True
False True True True
False False False False

Write code · Hard

Prove De Morgan. For all four combinations of a and b, print not (a and b) next to (not a) or (not b), and not (a or b) next to (not a) and (not b), to show that each pair always matches.

Print four lines, for the combinations in this order: True True, True False, False True, False False. On each line print the four expressions in the order of the question, with one print and commas.

The program prints the lines below. Your program must print exactly these lines.

Example run

False False False False
True True False False
True True False False
True True True True

Write code · Hard

Safe ratio. For each pair (goals, matches) of (10, 0), (10, 4) and (10, 2), print whether the player averages more than 2.5 goals per match. The first pair must not crash. Use short-circuiting.

Print three lines, one for each pair in the order given: True or False.

The program prints the lines below. Your program must print exactly these lines.

Example run

False
False
True

Chapter project: Ride gate

Project

Who may go on the ride? A theme park ride has two rules. The rider must be from 120 to 195 cm tall, inclusive. And the rider must be 12 years old or more, or be with an adult.

Check these three riders, in this order:

  1. name "Maya", height 150, 14 years old, not with an adult
  2. name "" (the name was left empty), height 118, 30 years old, with an adult
  3. name "Leo", height 125, 9 years old, with an adult

For each rider, print one line with three values, using one print and commas: the name (or the text Guest when the name is empty), whether the height is in the range, and whether the rider may go on the ride.

Keep the last value of each rider in its own variable. Finish with a fourth line: the text Riders let in: and then how many of the three riders may go, found by adding the three stored Booleans.

The program prints the lines below. Your program must print exactly these lines.

Example run

Maya True True
Guest False False
Leo True True
Riders let in: 2