Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

2.3 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
694596b0585c11170ac7c7f9 Challenge 161: Free Shipping 29 challenge-161

--description--

Given an array of strings representing items in your shopping cart, and a number for the minimum order amount to qualify for free shipping, determine if the items in your shopping cart qualify for free shipping.

The given array will contain items from the list below:

Item Price
"shirt" 34.25
"jeans" 48.50
"shoes" 75.00
"hat" 19.95
"socks" 15.00
"jacket" 109.95

--hints--

gets_free_shipping(["shoes"], 50) should return True.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(gets_free_shipping(["shoes"], 50), True)`)
}})

gets_free_shipping(["hat", "socks"], 50) should return False.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(gets_free_shipping(["hat", "socks"], 50), False)`)
}})

gets_free_shipping(["jeans", "shirt", "jacket"], 75) should return True.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(gets_free_shipping(["jeans", "shirt", "jacket"], 75), True)`)
}})

gets_free_shipping(["socks", "socks", "hat"], 75) should return False.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(gets_free_shipping(["socks", "socks", "hat"], 75), False)`)
}})

gets_free_shipping(["shirt", "shirt", "jeans", "socks"], 100) should return True.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(gets_free_shipping(["shirt", "shirt", "jeans", "socks"], 100), True)`)
}})

gets_free_shipping(["hat", "socks", "hat", "jeans", "shoes", "hat"], 200) should return False.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(gets_free_shipping(["hat", "socks", "hat", "jeans", "shoes", "hat"], 200), False)`)
}})

--seed--

--seed-contents--

def gets_free_shipping(cart, minimum):

    return cart

--solutions--

def gets_free_shipping(cart, minimum):
    prices = {
        "shirt": 34.25,
        "jeans": 48.50,
        "shoes": 75.00,
        "hat": 19.95,
        "socks": 15.00,
        "jacket": 109.95
    }

    total = 0

    for item in cart:
        total += prices[item]

    return total >= minimum