Home > other >  Design a commodity in Python classes
Design a commodity in Python classes

Time:10-13

Design a commodity in Python class, the class has a product id, name, price, quantity, application of this class, statistical, total amount of the three kinds of goods how to do!!!!!!!!!!!

CodePudding user response:

Can put the goods attribute do in class initializes the init, can use the list set of tuples [(article number 1, name, price, quantity), (article number 2, name, price, quantity)... List, or set of dictionary [article number 1: (name, price, quantity), article number 2: (name, price, quantity)... Method of adding goods, do a, to do a statistical method, the total amount of traverse the list, the price is the product of the number of accumulation, called when creating an instance, use method of adding items to create commodity information list first, then calls to get the results of the total amount of the statistical method
  • Related