class Rectangle:
def __init__(self, width, length):
self.width = width
self.length = length
# def change_width(self, new_width):
# self.width = new_width
# def _change_length(self, new_length):
# self.length = new_length
def per(self):
return (self.length + self.width) * 2
def area(self):
return self.length * self.width
def print_info(self):
print("Заданий прямокутник довжиною", str(self.length), "та шириною", str(self.width))
print("Його площа:", str(self.area()))
print("Його периметр:", str(self.per()))
rectangle = Rectangle(10, 20)
ar = rectangle.area()
pr = rectangle.per()
new_length = int(input('Введіть довжину:'))
new_width = int(input("Введіть ширину:"))
rectangle._change_length(new_length)
rectangle.change_width(new_width)
rectangle.print_info()
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
class Rectangle:
def __init__(self, width, length):
self.width = width
self.length = length
# def change_width(self, new_width):
# self.width = new_width
# def _change_length(self, new_length):
# self.length = new_length
def per(self):
return (self.length + self.width) * 2
def area(self):
return self.length * self.width
def print_info(self):
print("Заданий прямокутник довжиною", str(self.length), "та шириною", str(self.width))
print("Його площа:", str(self.area()))
print("Його периметр:", str(self.per()))
rectangle = Rectangle(10, 20)
ar = rectangle.area()
pr = rectangle.per()
new_length = int(input('Введіть довжину:'))
new_width = int(input("Введіть ширину:"))
rectangle._change_length(new_length)
rectangle.change_width(new_width)
rectangle.print_info()