Я опять обращаюсь за помощью... Дам 20б
Нужен код
Створіть програму з будь-якими геометричними фігурами
Ответы
Ответ:
import math
class Shape:
def area(self):
pass
def perimeter(self):
pass
class Circle(Shape):
def __init__(self, radius):
self.radius = radius
def area(self):
return math.pi * self.radius ** 2
def perimeter(self):
return 2 * math.pi * self.radius
class Rectangle(Shape):
def __init__(self, width, height):
self.width = width
self.height = height
def area(self):
return self.width * self.height
def perimeter(self):
return 2 * (self.width + self.height)
while True:
print('Choose a shape to create:')
print('1. Circle')
print('2. Rectangle')
print('3. Quit')
choice = input('Enter your choice: ')
if choice == '1':
radius = float(input('Enter the radius of the circle: '))
circle = Circle(radius)
print('Area of the circle:', circle.area())
print('Perimeter of the circle:', circle.perimeter())
elif choice == '2':
width = float(input('Enter the width of the rectangle: '))
height = float(input('Enter the height of the rectangle: '))
rectangle = Rectangle(width, height)
print('Area of the rectangle:', rectangle.area())
print('Perimeter of the rectangle:', rectangle.perimeter())
elif choice == '3':
break
else:
print('Invalid choice. Please try again.')
Объяснение:
на python