Variables, Types & Operators · Question 11 · Medium

A voter-age check uses chained comparisons. What does it print for age 21?

age = 21
print(18 <= age < 21, 18 <= age <= 21)
  1. False True
  2. True True
  3. False False
  4. True False
Answer and explanation

Answer: A. False True

Explanation: 18 <= age < 21 means 18 <= age and age < 21; 21 < 21 is False, so the first result is False. In the second chain 21 <= 21 is True, so it is True.

Previous: How many values in the list vals are treated as true by the if test? · Next: Two separate lists hold the same values and a third name points to the first…

Practise variables, types & operators

Try a fresh set of variables, types & operators questions with an explanation after every answer, free and without signing up: Variables, Types & Operators practice. Or sit a full placement mock test.

More variables, types & operators questions

More python practice

Python Strings · Lists & Tuples · Dictionaries & Sets · Conditions & Loops · Functions & Scope · Comprehensions & Generators · Classes & Objects · Exceptions & Files

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge