云运维开发双12促销活动通常是指在每年的12月12日这一天,云服务提供商为了吸引更多的用户使用其云服务,推出的一系列优惠活动和折扣。这些活动可能包括:
import datetime
class Promotion:
def __init__(self, name, discount_rate, start_date, end_date):
self.name = name
self.discount_rate = discount_rate
self.start_date = start_date
self.end_date = end_date
def is_active(self):
today = datetime.date.today()
return self.start_date <= today <= self.end_date
def apply_discount(self, original_price):
if self.is_active():
return original_price * (1 - self.discount_rate)
else:
return original_price
# 示例使用
promotion = Promotion("双12大促", 0.2, datetime.date(2023, 12, 12), datetime.date(2023, 12, 12))
original_price = 100
discounted_price = promotion.apply_discount(original_price)
print(f"原价: {original_price}, 折扣后价格: {discounted_price}")
通过上述代码,可以管理促销活动的有效期和应用折扣。希望这些信息对你有所帮助!
领取专属 10元无门槛券
手把手带您无忧上云