Objective
Instance attributes are different in each object; class attributes are shared by all of them. A @classmethod works with the class and a @staticmethod is an ordinary function grouped inside it.
Instructions
- Define the class
Productwith a class attributetotal(it starts at 0) that increases by 1 each time a product is created, and instance attributesnameandprice. - Add a class method
how_many()that returns the total, and a static methodwith_vat(price, vat=21)that returns the price with VAT applied (21by default). - Read
nand thennlinesname price. Create each product and showname: price -> price with VAT(two decimals). - At the end show
Total created: n.
2
pan 1.50
leche 0.90
pan: 1.50 -> 1.81
leche: 0.90 -> 1.09
Total created: 2
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise