-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem 1.py
More file actions
38 lines (31 loc) · 1.43 KB
/
Copy pathProblem 1.py
File metadata and controls
38 lines (31 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
""" Problem 1: Create a Python class called Circle with constructor which will
take a list as an argument for the task. The list is [10,501,22,37,100,999,87,351].
Problem 2: Create proper member variable inside the task if required and use
them when necessary. For example for this task create a class
private variable named pi=3.141
Problem 3: From the list create two class methods Area and Perimeter which will be going
to calculate the area and perimeter."""
# Created a class 'Circle'
class Circle:
# Constructor with list as an argument
def __init__(self,listn):
self.listn=listn
print(listn)
# Private variable
self.__pi=3.141
# Method for calculating the Area for the values in the list
def AreaOfCircle(self):
# Iterate through the list to calculate the area
for i in self.listn:
area= self.__pi*i*i
print("The area of ",i,":",area)
# Method for calculating the Perimeter for the values in the list
def PerimeterOfCircle(self):
for i in self.listn:
perimeter= 2*self.__pi*i
print("The perimeter of ",i,":",perimeter)
# Created an object for the class Circle with list as a parameter
obj= Circle([10,501,22,37,100,999,87,351])
# Using object to access the class methods
obj.AreaOfCircle()
obj.PerimeterOfCircle()