Final answer:
To create a simple class definition for a 'Product' object in Python, use the __init__() constructor method to receive three pieces of information about the product.
Define two methods for returning the Discount Amount and the Discounted Price. Create two instances of the 'Product' object and print their information.
Step-by-step explanation:
To create a simple class definition for a 'Product' object in Python, you can use the __init__() constructor method. This method should receive three pieces of information about the product (name, price, and discountPercent) as parameters. Inside the class, you can define two methods: one for returning the Discount Amount and another for returning the Discounted Price.
- To calculate the Discount Amount, you can divide the discountPercent argument by 100 and multiply it by the price.
- To calculate the Discounted Price, you can subtract the Discount Amount from the price. In this calculation, you can call the Discount Amount method from the Discounted Price method, instead of repeating the formula.
In the same .py file as your Product class, you can create two separate instances of the 'Product' object. You can either hard-code the parameter values or prompt the user for input.
For example:
class Product:
To print the product information to the screen, you can access the arguments and methods of the product instances. For example:
print(f'Product 1 - Name: {product1.name}, Discounted Price: {product1.get_discounted_price()}')