• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# SUPyF2 Objects/Classes-Lab - 05. Circle

SimeonTs Oct 18th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. """
2. Objects and Classes - Lab
4.
5. SUPyF2 Objects/Classes-Lab - 05. Circle
6.
7. Problem:
8. Create a class Circle. In the __init__ method the circle should only receive one parameter (its diameter).
9. Create a class attribute called __pi that is equal to 3.14. The class should also have the following methods:
10. • calculate_circumference() - returns the circumference of the circle
11. • calculate_area() - returns the area of the circle
12. • calculate_area_of_sector(angle) - given the central angle in degrees, returns the area that fills the sector
13. Notes: Search the formulas in the internet. Name your methods and variables exactly as in the description!
14. Submit only the class. Test your class before submitting!
15.
16. Example:
17. Test Code:
18.
19. circle = Circle(10)
20. angle = 5
21.
22. print(f"{circle.calculate_circumference():.2f}")
23. print(f"{circle.calculate_area():.2f}")
24. print(f"{circle.calculate_area_of_sector(angle):.2f}")
25.
26. Output:
27. 15.70
28. 78.50
29. 1.09
30. """
31.
32.
33. class Circle:
34.     __pi = 3.14
35.
36.     def __init__(self, diameter):
37.         self.diameter = diameter
38.         self.radius = diameter / 2
39.
40.     def calculate_circumference(self):
42.
43.     def calculate_area(self):
45.
46.     def calculate_area_of_sector(self, angle):