Ask Question
24 November, 21:51

Create a geometry application For this exercise you will create a module named 'shapes. py' and a program that uses it. The module will contain two classes: Circle and Rectangle. • Start with the class example (Module 10, part 1b) as a basis for Circle o Add an attribute and getter method for the perimeter (distance around the outside, officially called the circumference). • Write a class named Rectangle to represent a rectangle. The class should contain: o Two attributes that specify the length and the width. These should initially be set when the object is created with __init__. o Setter and getter methods for length and width. o Attributes and getter methods for the area and the perimeter. Then write a main program that will use the module.

+5
Answers (1)
  1. 24 November, 22:19
    0
    See explaination

    Explanation:

    # shapes. py

    import math class Circle: def __init__ (self, radius = 0) : self.__radius = radius self.__area = math. pi * self.__radius * * 2 self.__circumference = 2 * math. pi * self.__radius def set_radius (self, radius) : self.__radius = radius self.__area = math. pi * self.__radius * * 2 self.__circumference = 2 * math. pi * self.__radius def get_radius (self) : return self.__radius def get_area (self) : return self.__area def get_circumference (self) : return self.__circumference class Rectangle: def __init__ (self, length = 0, breadth = 0) : self.__length = length self.__breadth = breadth self.__calc_area () self.__calc_perimeter () def __calc_area (self) : self.__area = self.__length * self.__breadth def __calc_perimeter (self) : self.__perimeter = 2 * (self.__length + self.__breadth) def set_length (self, length) : self.__length = length self.__calc_area () self.__calc_perimeter () def set_breadth (self, breadth) : self.__breadth = breadth self.__calc_area () self.__calc_perimeter () def get_length (self) : return self.__length def get_breadth (self) : return self.__breadth def get_area (self) : return self.__area def get_perimeter (self) : return self.__perimeter

    # testShapes. py (Main program)

    import shapes if __name__ = = "__main__": print ("a. Circle") print ("b. Rectangle") choice = input ("/nChoose a Shape to continue: ") if choice = = "a": radius = int (input ("/nEnter Radius of the Circle: ")) myCircle = shapes. Circle (radius) print ("/nArea of Circle:", myCircle. get_area ()) print ("Circumference of Circle:", myCircle. get_circumference ()) reset = input ("Do you want to change Radius (y/n) : ") if reset = = "y" or reset = = "Y": radius = int (input ("/nEnter new Radius of the Circle: ")) myCircle = shapes. Circle (radius) print ("/nArea of Circle:", myCircle. get_area ()) print ("Circumference of Circle:", myCircle. get_circumference ()) elif choice = = "b": length = int (input ("/nEnter length of Rectangle: ")) breadth = int (input ("Enter breadth of Rectangle: ")) myRectangle = shapes. Rectangle (length, breadth) print ("/nArea of Rectangle:", myRectangle. get_area ()) print ("Perimeter of Rectangle:", myRectangle. get_perimeter ()) reset = input ("Do you want to change Length and Breadth (y/n) : ") if reset = = "y" or reset = = "Y": length = int (input ("/nEnter new length of Rectangle: ")) breadth = int (input ("Enter new breadth of Rectangle: ")) myRectangle = shapes. Rectangle (length, breadth) print ("/nArea of Rectangle:", myRectangle. get_area ()) print ("Perimeter of Rectangle:", myRectangle. get_perimeter ()) else: print ("Invalid choice! / '", choice, "/'/nExiting ... ")
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Create a geometry application For this exercise you will create a module named 'shapes. py' and a program that uses it. The module will ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers