Mid-Level
October 4, 2026Spot the bug: Django
One snippet. Find the bug, or prove there isn't one.
python
1from django.core.cache import cache
2from .models import Product
3
4def get_product_price(product_id, discount_codes=[]):
5 product = Product.objects.get(pk=product_id)
6 price = product.price
7 if product.on_sale:
8 discount_codes.append('AUTO_SALE')
9 for code in discount_codes:
10 price = apply_discount(price, code)
11 return price
12
13def apply_discount(price, code):
14 rate = cache.get(f'discount:{code}', 0)
15 return price * (1 - rate)Click the lines that carry the problem.
Your verdict
One attempt per day. The answer shows up right after.
Keep your streak
Create an account to keep your streak and track your progress.