利用类来解答这个问题。
pack1, price1 = 50, 24.59
pack2, price2 = 25, 11.99
class result:
def __init__(self,pack,price):
self.pack = pack
self.price = price
def set_pack(self):
return self.pack
def set_price(self):
return self.price
def get_result(self):
return self.price / self.pack
a = 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')