Question
Using the Circle class implementation in class... import math class Circle: create a circle class that allows you to set the radius, get the
Using the Circle class implementation in class...
import math
class Circle: """ create a circle class that allows you to set the radius, get the radius, calculate the area and compare two different circles""" def __init__(self, radius = 0): """constructs a circle object""" #under your constructor you place any attributes self.radius = radius def setRadius(self, radius): """ set the radius post: will update the radius with a new value""" self.radius = radius def getRadius(self): """ post: returns the radius to point of call""" return self.radius def area(self): """ post: returns the area of the cirle object""" return ((self.radius**2) * math.pi) def circumference(self): """ post: returns the circumference of the object""" return (2 * math.pi * self.radius) def show(self): """ post: diplays our circle stuff""" print(" ", "radius: ", self.radius) print(" area: ", self.area()) print(" circumference: ", self.circumference(), " ") # operator overloading def __add__(self, other): #other is another circle object """pre: two circle objects with a plus sign between post: a new circle object with the radius = c1+c2""" return Circle(other.radius + self.radius) def __str__(self): """pre: a circle object post: return the values associated with the object as a string""" return " Circle with radius " + str(self.radius) def __lt__(self, other): """pre: two circle objects post: returns a boolean to say if the statement (c1
define a second subclass called Cone with:
Attributes for radius and height
Methods for calculating volume, surface area and appropriate getters and setters (for height attribute).
Overload the __str__ operator to allow display of the cone data
Demonstrate the amazing new class implementation in your driver by displaying the radius (using the getRadius() function), and volume and surface area (using the __str__ overload in a print function).
import circle
def main(): c1 = circle.Circle(4) print("The radius of c1 : ", c1.getRadius()) c2 = circle.Circle() print("The radius of c2: ", c2.getRadius()) c1.setRadius(6) print("The new radius of c1 : ", c1.getRadius()) c3 = circle.Circle(12) c3.show() c4 = c1 + c2 #creates a new circle object with the sum of two objects radius print(c4) print(c4 > c2) print(c1 < c2)
print (c3 == c2) cyl = circle.Cylinder(4,2) print(cyl.getRadius()) main()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started