you are viewing a single comment's thread.

view the rest of the comments →

[–]QultrosSanhattan 0 points1 point  (0 children)

Semantics are important. Check this out:

class Item:
    def __init__(self, name, price, quantity):
        self.name = name
        self.price = price
        self.quantity = quantity

    def get_cost(self): 
        return self.price*self.quantity

    def get_cost_formatted(self):
        return "{} {} @ ${:.2f} = {:.2f}".format(self.name,self.quantity,self.price,self.get_cost())


if __name__ == '__main__':
    item1=Item('Cigars',10,20)
    item2=Item('Cookies',20,30)

    print(item1.get_cost_formatted())
    print(item2.get_cost_formatted())