《Python语言程序设计》2018 第4章第9题3重量和价钱的对比,利用第7章的概念来解答你
利用类来解答这个问题。
pack1, price1 = 50, 24.59
pack2, price2 = 25, 11.99class result:def __init__(self,pack,price):self.pack = packself.price = pricedef set_pack(self):return self.packdef set_price(self):return self.pricedef get_result(self):return self.price / self.packa = result(pack1,price1)
b = result(pack2,price2)if a.get_result() < b.get_result():print('pack1 has the better pack2')
else:print('pack2 has the better pack1')