Orta seviye
4 Ekim 2026

Hatayı bul: Django

Tek bir kod parçası. Hatayı bul ya da hata olmadığını kanıtla.

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)

Soruna yol açan satırlara tıkla.

Kararın

Günde bir deneme. Cevap hemen ardından görünür.

Serini koru

Serini korumak ve ilerlemeni takip etmek için hesap oluştur.

Hesap oluştur