Advertisement
SimeonTs

SUPyF2 Objects/Classes-Lab - 05. Circle

Oct 18th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.63 KB | None | 0 0
  1. """
  2. Objects and Classes - Lab
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1733#4
  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):
  41.         return Circle.__pi * self.radius
  42.  
  43.     def calculate_area(self):
  44.         return Circle.__pi * self.radius * self.radius
  45.  
  46.     def calculate_area_of_sector(self, angle):
  47.         return (angle / 360) * Circle.__pi * self.radius * self.radius
  48. #
  49. # circle = Circle(10)
  50. # angle = 5
  51. #
  52. # print(f"{circle.calculate_circumference():.2f}")
  53. # print(f"{circle.calculate_area():.2f}")
  54. # print(f"{circle.calculate_area_of_sector(angle):.2f}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement