Chained Comparison in Python
Level 396 keystrokes
This uses Python's chained comparison operators. The expression 0 <= value <= 100 checks if value is between 0 and 100 inclusive.
Python code
# Returns whether value lies between 0 and 1001def check_range(value): # Chained comparison: same as 0 <= value and value <= 100 (both ends included)2 return 0 <= value <= 1003 # 0 <= 50 <= 100 holds, so this prints True4print(check_range(50))# 150 <= 100 fails, so this prints False5print(check_range(150))Output
True False
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this Python code and how often they appear.
(× 5)× 5_× 3<× 2=× 2:× 1