1. Define a class Circle with attribute radius.
2. Define the following:
• A class variable count which determines the number of circles created.
• A method area that calculates the area of a circle.
3. The input should be comma-separated-values, while the output should be the area for each value and the total number of circles created.
4. Check the main/tail section for output handling (read-only).
5. Use the Test against custom input box to output the result for debugging,
6. Provide float values separated by comma (refer test case samples) to display the output/error. The outputs should be split into 2 lines:
• The 1st output should return the area of the circles for which inputs were provided.
• The 2nd output should return the number of circles created for the number of inputs provided.
import os import sys #Add Circle class implementation below class Circle(object): no_of_circles = 0 def __init__(self, radius): self.__radius = radius Circle.no_of_circles += 1 def getCirclesCount(self): return Circle.no_of_circles @staticmethod def square(x): return x**2 def area(self): return 3.14*self.square(self.__radius) '''Check the Tail section for input/output''' if __name__ == "__main__": with open(os.environ['OUTPUT_PATH'], 'w') as fout: res_lst = list() lst = list(map(lambda x: float(x.strip()), input().split(','))) for radius in lst: res_lst.append(Circle(radius).area()) fout.write("{}\n{}".format(str(res_lst), str(Circle.no_of_circles)))
First read the answer fully, then try to explain it in your own words. After that, open a few related questions and compare the concepts. This method helps you remember the topic for a longer time and improves exam preparation.