Question
in python: how fix the code below so that the output will print out on decimal place? the rounding should be at the print area.
in python: how fix the code below so that the output will print out on decimal place? the rounding should be at the print area.
class Rectangle: """ Rectangle class """ def __init__(self, width=1, height=2): """ Constructor """ # Initializing private variables self.__width = width; self.__height = height; def getWidth(self): """ Function that returns width of a rectangle """ return self.__width; def getHeight(self): """ Function that returns height of a rectangle """ return self.__height; def getArea(self): """ Function that returns area of a rectangle """ return self.__width * self.__height; def getPerimeter(self): """ Function that returns perimeter of a rectangle """ return 2 * (self.__width + self.__height);
def main(): """ Main function """ # Creating object rect = Rectangle(4, 40); # Printing data print(" A " + str(rect.getWidth()) + " x " + str(rect.getHeight()) + " rectangle has an area of " + str(rect.getArea()) + " and a perimeter of " + str(rect.getPerimeter()) + ". "); # Creating object rect1 = Rectangle(3.5, 35.7); # Printing data print(" A " + str(rect1.getWidth()) + " x " + str(rect1.getHeight()) + " rectangle has an area of " + str(rect1.getArea()) + " and a perimeter of " + str(rect1.getPerimeter()) + ". ");
# Calling main function 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