0% found this document useful (0 votes)
28 views5 pages

Activity I (Circle Class) Problem/Scenario:: Lopez, Michaela Yzabel D. Cpe 105-Cpe12Fa1 TTH 10:30-1:30

The document describes a Python program that defines a Circle class with methods to set radius and color, calculate area and circumference, and display circle characteristics. The program creates a Circle object, sets its radius to 5 and color to "Blue", calculates and displays its area and circumference, then displays its characteristics. It then changes the color to "Red" and again displays the characteristics.

Uploaded by

Soleil Salvador
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views5 pages

Activity I (Circle Class) Problem/Scenario:: Lopez, Michaela Yzabel D. Cpe 105-Cpe12Fa1 TTH 10:30-1:30

The document describes a Python program that defines a Circle class with methods to set radius and color, calculate area and circumference, and display circle characteristics. The program creates a Circle object, sets its radius to 5 and color to "Blue", calculates and displays its area and circumference, then displays its characteristics. It then changes the color to "Red" and again displays the characteristics.

Uploaded by

Soleil Salvador
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Lopez, Michaela Yzabel D.

CPE 105-CPE12FA1
TTh 10:30-1:30

Activity I (Circle Class)

Problem/Scenario:
Write a python program using class with given methods. 
The output of code is shown below:
class Circle:
def Circle():
def setRadius(radius):
def setColor(color):
def getArea():
def getCircum():
def info():
#----------------------------------------#
c=Circle()                                     # line 1
c.setRadius(5)                          # line 2
c.setColor("Blue")                  # line 3
c.getArea()                                 # line 4
c.getCircum()                           # line 5
c.info()                                          # line 6
c.setColor("Red")                  # line 7
c.info() # line 8
#----------------------------------------#
Radius = 5                                    # line 2 output
Color = Blue                               # line 3 output
Area = 78.54                              # line 4 output
Circumference = 31.42       # line 5 output
-----------------------------      # line 6 output
Circle Characteristics
-----------------------------
Radius = 5
Color = Blue
Circumference = 31.42
Area = 78.54
-----------------------------
Color = Red                              # line 7 output
-----------------------------    # line 8 output
Circle Characteristics
-----------------------------
Radius = 5
Color = Red
Circumference = 31.42
Area = 78.54
-----------------------------

Program Source Code:


class Cirlce:

counter = 0

def setRadius(self, radius):


print("Radius = " + str(radius))
self.radius = radius

def setColor(self, color):


print("Color = " + color)
self.color = color

def getArea(self):
self.area = (self.radius * self.radius) * 3.141592
area = "{:,.2f}".format(self.area)
print("Area = " + area)

def getCircum(self):
self.circumference = 2 * self.radius * 3.141592
circumference = "{:,.2f}".format(self.circumference)
print("Circumference = " + circumference)

def getInfo(self):
if self.counter == 0:
print("-----------------------")
print("Circle Characteristics")
print("-----------------------")
print("Radius = " + str(self.radius))
print("Color = " + self.color)
self.circumference = 2 * self.radius * 3.141592
circumference = "{:,.2f}".format(self.circumference)
print("Circumference = " + circumference)
self.area = (self.radius * self.radius) * 3.141592
area = "{:,.2f}".format(self.area)
print("Area = " + area)
print("-----------------------")
self.counter = self.counter + 1
else:
print("-----------------------")
print("Circle Characteristics")
print("-----------------------")
print("Radius:\t\t" + str(self.radius))
print("Color:\t\t" + self.color)
self.circumference = 2 * self.radius * 3.141592
circumference = "{:,.2f}".format(self.circumference)
print("Circumference:\t" + circumference)
self.area = (self.radius * self.radius) * 3.141592
area = "{:,.2f}".format(self.area)
print("Area:\t\t" + area)
print("-----------------------")
self.counter = self.counter + 1
e = Cirlce()
e.setRadius(5)
e.setColor("Blue")
e.getArea()
e.getCircum()
e.getInfo()
e.setColor("Red")
e.getInfo()

Program Output:

You might also like