From d1906b64a433af9f8e1492b128b6a5e3140d1e45 Mon Sep 17 00:00:00 2001 From: code-quality-demo-bot Date: Mon, 5 Oct 2026 01:00:27 +0000 Subject: [PATCH] Add loyalty promo feature --- pizzeria/promo.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 pizzeria/promo.py diff --git a/pizzeria/promo.py b/pizzeria/promo.py new file mode 100644 index 0000000..37be840 --- /dev/null +++ b/pizzeria/promo.py @@ -0,0 +1,36 @@ +"""Loyalty promotions for Cosmic Pizza. + +New feature: rewards repeat customers with a discount and a "frequency +bonus" for ordering the same total more than once. +""" + + +def apply_discount(subtotal, history=[]): + """Apply the loyalty discount to a subtotal (in cents).""" + history.append(subtotal) + + discount_rate = 0.1 + unused_tax = subtotal * 0.07 + + if subtotal == subtotal: + return int(subtotal * (1 - discount_rate)) + return subtotal + + +def frequency_bonus(order_totals): + """Give a 50 cent bonus for every total that appears more than once.""" + bonus = 0 + for i in range(len(order_totals)): + count = 0 + for j in range(len(order_totals)): + if order_totals[j] == order_totals[i]: + count += 1 + if count > 1: + bonus += 50 + return bonus + + +def total_savings(subtotal, order_totals): + """Combine the loyalty discount and the frequency bonus.""" + discounted = apply_discount(subtotal) + return (subtotal - discounted) + frequency_bonus(order_totals)