Python Programming - Objects - Discussion

Discussion Forum : Objects - General Questions (Q.No. 11)
11.
Consider the following Python code:
class Rectangle:
    def __init__(self, length, width):
        self.length = length
        self.width = width

    def calculate_perimeter(self):
        return 2 * (self.length + self.width)
If you create an instance of the `Rectangle` class called `my_rectangle` with length 4 and width 6, what will be the result of calling my_rectangle.calculate_perimeter()?
10
20
24
30
Answer: Option
Explanation:
The calculate_perimeter method calculates the perimeter of the rectangle using the formula 2 * (length + width). For the given instance, it would be 2 * (4 + 6) = 24.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.