Comparisons and booleans
A comparison produces a bool, which is either True or False. A bool is an ordinary value: you can store it in a name, return it or print it.
age = 17
is_adult = age >= 18
print(is_adult) # False
print(3 == 3.0, 3 != 4) # True True
print("apple" < "banana") # True
print("Zebra" < "apple") # True
print(True + True) # 2
print(sum([True, False, True])) # 2==and!=test equality.<,<=,>and>=test order.- Strings compare character by character, by code point, so every capital letter sorts before every lowercase one. Compare
a.lower()withb.lower()when case should not matter. boolis a kind ofint:Truecounts as 1 andFalseas 0, sosumover bools counts the true ones.1 < "2"raisesTypeError, while1 == "1"is simplyFalse.
Return the comparison
return x > 0 already is True or False. Wrapping it in an if that returns True or False adds lines and room for mistakes.
Your task
Write is_teen(age) returning True for ages 13 to 19 inclusive and False otherwise. Write count_passing(scores, pass_mark) returning how many scores are at least pass_mark.
The explanation opens here once every check passes.