Beispiel #1
0
    def reward_coupons(self, customer: Customer, rule: Type[CouponRule],
                       num: int) -> List[Coupon]:
        # Problem 1.3: YOUR CODE HERE
        if rule in self.available_coupon_types():
            if len(self.coupon_inventory[rule]) <= num:
                coupons_rewarded = self.coupon_inventory[rule]
                self.coupon_inventory[rule] = []
            else:
                coupons_rewarded = self.coupon_inventory[rule][0:num]
                self.coupon_inventory[rule] = self.coupon_inventory[rule][
                    num:len(self.coupon_inventory[rule])]
            customer.add_coupons(coupons_rewarded)
            return coupons_rewarded

        return []
Beispiel #2
0
  def reward_coupons(self, customer: Customer, rule: Type[CouponRule], num: int) -> List[Coupon]:

    assert num >= 0, f"Cannot award {num} coupons since {num} < 0!"

    # Initialize empty list of coupons
    coupons_list = []
    coupon_rule_length = len(self.coupon_inventory[rule])

    # If store's coupons for that type are less than what customer needs, return a list of all coupons for that type
    if num >= coupon_rule_length:
      coupons_list = self.coupon_inventory[rule]
      del self.coupon_inventory[rule]

    # If not, return the first num coupons from the store, and remove it from the store
    else:
      coupons_list = self.coupon_inventory[rule][0:num]
      self.coupon_inventory[rule] = self.coupon_inventory[rule][num:coupon_rule_length]

    customer.add_coupons(coupons=coupons_list)
    return coupons_list