class Selling:
def __init__(self, num, price, rate, whole_num):
self.num = num
self.price = price
self.rate = rate
self.whole_num = whole_num
def record_nun(self):
return self.num
def total_amount(self):
if self.num < self.whole_num:
amount = self.num * self.price
else:
amount = self.price * self.rate * self.num
return amount
t = Selling(20, 150, 0.7, 200)
r_num = t.record_nun()
t_amount = t.total_amount()
print('你购买的数量:{0}本,总价:{1}元.' .format(str(r_num), str(t_amount)))
python大学实用教程练习6.11(商品销售类)
最新推荐文章于 2022-12-02 23:12:12 发布