1. Lighthouse

Level 7 · Which loyalty tier is she in?

The request

From Jordan Reyes, Head of Marketing

“Gold is $1,000+ spent AND at least 5 orders. Silver is $500+ spent OR 10+ orders. Everyone else is bronze. Which tier is this customer? The CRM name field is messy, so tidy it for the label.”

Your goal

Set result to a str of the form "Dana Whitfield: silver": the name with surrounding spaces removed and each word capitalized, a colon and a space, then the tier in lowercase. Tier rules: 'gold' if spend is at least 1000 and orders is at least 5; otherwise 'silver' if spend is at least 500 or orders is at least 10; otherwise 'bronze'.

  • Store a text value (str) in resultnot done yet

Your code

Python

Loading the editor…

    ResultPress Run to see yours

    Mote checks your result

    Press Run. Each row that matches the goal becomes a firefly in your lantern.

    The lesson

    and, or and the order of the branches

    and is true only when both sides are true. or is true when at least one side is. Gold uses and and silver uses or, and that difference decides Dana’s tier:

    spend >= 1000 and orders >= 5    # True and False  -> False
    spend >= 500 or orders >= 10     # True or False   -> True

    An if/elif/else chain stops at the first true branch, so the order matters. Put the most demanding tier first. If silver came first, a customer with $3,000 and 20 orders would match silver and the gold branch would never run.

    if spend >= 1000 and orders >= 5:
        tier = "gold"
    elif spend >= 500 or orders >= 10:
        tier = "silver"
    else:
        tier = "bronze"

    A customer with $200 spent and 12 orders lands in silver through the orders side of the or. A customer with $480 and 3 orders falls through to bronze.

    When a rule mixes and and or in one line, add parentheses so the grouping is obvious to the next reader: (spend >= 1000 and orders >= 5) or vip. Python evaluates and before or, but nobody should have to remember that to review a business rule. Short, explicit conditions are also much easier to test one at a time when a customer asks why they ended up in the wrong tier.

    Cleaning text before you show it

    Names typed into a CRM arrive with stray spaces and random capitals. String methods return a new, cleaned string and can be chained:

    "  dana WHITFIELD ".strip()           # 'dana WHITFIELD'
    "  dana WHITFIELD ".strip().title()   # 'Dana Whitfield'

    .title() capitalizes the first letter of each word and lowercases the rest. It’s fine for most names, but it isn’t perfect: “mcallister” becomes “Mcallister”, not “McAllister”. For a quick label that is usually acceptable; for a mailing you’d want a cleaner source.

    Building the label

    An f-string drops values into text. Anything inside the braces is evaluated, including method calls:

    f"{name.strip().title()}: {tier}"     # 'Dana Whitfield: silver'

    Common mistakes

    • Swapping and and or between the tiers. The words in the policy (“and”, “or”) map directly to the Python keywords, so copy them across carefully.
    • Using > where the rule says “at least”. $1,000 exactly is gold territory, so the test is >=.
    • Putting silver before gold.
    • Calling .title() but forgetting .strip(), which leaves spaces at the start of the label.

    Pick what may run on this site. You can change this any time from "Cookie settings" at the bottom of every page.