Question: USE PYTHON3; DO NOT IMPORT ANY PACKAGES Please do all of part 1 Here's what the code looks like in the editor: class Product:
USE PYTHON3; DO NOT IMPORT ANY PACKAGES
Please do all of part 1


Here's what the code looks like in the editor:
class Product: """ TODO: Complete the docstring. """
##### Part 1.1 ##### def __init__(self, name, price): """ TODO: Complete the docstring. """ # YOUR CODE GOES HERE # self.name = ... self.price = ... self.id = ...
def __str__(self): """ TODO: Complete the docstring. """ # YOUR CODE GOES HERE #
def __repr__(self): """ TODO: Complete the docstring. """ # YOUR CODE GOES HERE #
class Limited_Product(Product): """ TODO: Complete the docstring. """
##### Part 1.2 ##### def __init__(self, name, price, amount): """ TODO: Complete the docstring. """ # YOUR CODE GOES HERE # self.amount = ...
def __str__(self): """ TODO: Complete the docstring. """ # YOUR CODE GOES HERE #
class Special_Product(Product): """ TODO: Complete the docstring. """
##### Part 1.3 ##### def __init__(self, name, price, description="special"): """ TODO: Complete the docstring. """ # YOUR CODE GOES HERE # self.description = ...
def __str__(self): """ TODO: Complete the docstring. """ # YOUR CODE GOES HERE #
Thank you so much!
Part 1: Product The Product class provides abstraction to the products available in our system. Note that each Product instance represents a listing or kind of products, instead of an individual product. Unless the product is limited (Part 1.2), you can assume that the supply for this product is infinite. 1.1 Product You need to implement the following methods: 0 __init__(self, name, price) Initialize the following instance variables in the constructor: name (str) Product name. Initialize it with the name argument. price (int) Product price. Initialize it with the price argument. id (int) An auto-increment unique identifier of this product. Note: Auto-increment means that a new unique id number is generated when the instance is initialized, and you can compare the initialization time of two instances of this class by just comparing their auto-generated id. In this assignment, we will start from 0 (i.e. the first Product initialized has id 0), and increment by 1 after each initialization (i.e. the second Product has id 1, the third Product has id 2, etc.). You can create a class attribute to implement this feature. (call it product_counter) 0 _str_ (self) Return the string representation in this format: " {name} - {price}$" 0 __repr__ (self) Return the string representation in this format: "PRODUCT " (There is a space between "PRODUCT" and "") 1.2 Limited_Product A limited product is a kind of product that has a limited number of offerings. You need to implement the following methods: _init__(self, name, price, amount) Initialize the following instance variables in the constructor: name (str) Initialize them with the super constructor. price (int) id (int) amount (int) The amount of items available for this product. Initialize it with the amount argument. _str__(self) Return the string representation in this format: " {name} - {price}$ ({amount} left)" 1.3 Special_Product A special product is a product that sells to premium users only. You need to implement the following methods: 0 __init__(self, name, price, description) Initialize the following instance variables in the constructor: name (str) Initialize them with the super constructor. price (int) id (int) description A description to this product. Initialize it with the (str) description argument, or the default value "special" if this argument is not provided. _str__ (self) Return the string representation in this format: " {name} - {price} $ ({description})
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
