Apologies if this a basic question. I’m quite new to programming. I just finished working through this exercise and want to confirm that my understanding is correct.
class Circle: pi = 3.14 def area(self, radius): return self.pi * radius ** 2 circle = Circle() pizza_area = circle.area(12/2) teaching_table_area = circle.area(36/2) round_room_area = circle.area(11460/2)
In the above code snippet, I created a class called Circle with a class variable called pi. I then created a method within the class called area. In order to be able to use the class, I have to instantiate it by running circle = Circle(). When I run pizza_area = circle.area(12/2), I am calling my class and the method within that class. The value in parenthesis is my argument radius from the method divided by 2.
Is my understanding correct? One thing I’m not sure of is for return self.pi * radius **2, why do I have to use self.pi instead of just pi?
Thank you so much!