Exercises
Operators
3 tasks. Write the code, press Check, and the page runs it against a real Python interpreter.
Exercise 1Passed
Print True when age is at least 18 and under 65, using a single chained comparison.
Python
age = 25
# print the chained comparison
You can write the two bounds on either side of age.
age = 25
print(18 <= age < 65)Exercise 2Passed
Two lists hold the same numbers. Print whether they are equal, then whether they are the same object.
Python
a = [1, 2, 3]
b = [1, 2, 3]
# print equality, then identity
== asks about contents, is asks about identity.
a = [1, 2, 3]
b = [1, 2, 3]
print(a == b)
print(a is b)Exercise 3Passed
Add brackets so the expression gives 20 rather than 14.
Python
print(2 + 3 * 4)Multiplication binds tighter than addition unless you say otherwise.
print((2 + 3) * 4)