Python Programming - Objects - Discussion

Discussion Forum : Objects - General Questions (Q.No. 20)
20.
Consider the following Python code:
class Product:
    def __init__(self, name, price):
        self.name = name
        self.price = price

    def apply_discount(self, discount_percentage):
        discounted_price = self.price * (1 - discount_percentage / 100)
        return discounted_price
If you create an instance of the `Product` class called laptop with a price of 1000 and then call laptop.apply_discount(20), what will be the discounted price?
800
900
1000
1200
Answer: Option
Explanation:
The apply_discount method calculates the discounted price based on the given discount percentage. For the given instance, it would be 1000 * (1 - 20/100) = 800.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.