Have a go at it. The editor and the docs panel are open, and your code is saved as you type. Running it needs a free account — you’ll come back to exactly what you wrote.

Boolean Logic

~7 mincode completion

A boolean is either True or False (capitalised, always). Comparisons produce booleans, and you combine them with and, or and not:

age = 20
has_ticket = True

age >= 18                    # True
age >= 18 and has_ticket     # True   <- both must be true
age >= 65 or has_ticket      # True   <- at least one must be true
not has_ticket               # False

You can also chain comparisons, which reads exactly like maths:

0 <= score <= 100            # True when score is in range

And you do not need an if to return a boolean. This:

if x > 0:
    return True
else:
    return False

is just a longer way of writing return x > 0.

Your task:

Write is_valid_score(score) that returns True when score is a number between 0 and 100 inclusive, and False otherwise.

Example Tests

A score in the middle of the range is valid

Input: {"score":50}

Expected: true

0 is the bottom of the range and counts as valid

Input: {"score":0}

Expected: true

100 is the top of the range and counts as valid

Input: {"score":100}

Expected: true

Python
def is_valid_score(score):
    """
    Check whether a score is in the allowed range.

    Args:
        score: a number

    Returns:
        True if 0 <= score <= 100, otherwise False.
    """
    # YOUR CODE HERE
    pass

Run your code to see results

⌘↵ runs against the visible tests

Loading docs…