Срочно задание по информатикеЗадание 1. Напишите программу содержащую функции для расчета периметров прямоугольника, квадрата, треугольника, трапеции и ромба.
Задание 2. Напишите программу содержащую функцию для расчета данной формулы: (a+b)/4 + (a-b)/2 - c/a + b/c
Ответы на вопрос
Ответ:
1) Задание
def perimeter_rectangle(length, width):
"""Calculate the perimeter of a rectangle given its length and width.
Args:
length (float): The length of the rectangle.
width (float): The width of the rectangle.
Returns:
float: The perimeter of the rectangle.
"""
return 2 * (length + width)
def perimeter_square(side):
"""Calculate the perimeter of a square given its side length.
Args:
side (float): The side length of the square.
Returns:
float: The perimeter of the square.
"""
return 4 * side
def perimeter_triangle(side_a, side_b, side_c):
"""Calculate the perimeter of a triangle given the lengths of its sides.
Args:
side_a (float): The length of the first side of the triangle.
side_b (float): The length of the second side of the triangle.
side_c (float): The length of the third side of the triangle.
Returns:
float: The perimeter of the triangle.
"""
return side_a + side_b + side_c
def perimeter_trapezoid(side_a, side_b, height):
"""Calculate the perimeter of a trapezoid given the lengths of its bases and height.
Args:
side_a (float): The length of the first base of the trapezoid.
side_b (float): The length of the second base of the trapezoid.
height (float): The height of the trapezoid.
Returns:
float: The perimeter of the trapezoid.
"""
return side_a + side_b + 2 * height
def perimeter_rhombus(diagonal_a, diagonal_b):
"""Calculate the perimeter of a rhombus given the lengths of its diagonals.
Args:
diagonal_a (float): The length of the first diagonal of the rhombus.
diagonal_b (float): The length of the second diagonal of the rhombus.
Returns:
float: The perimeter of the rhombus.
"""
return 4 * (diagonal_a**2 + diagonal_b**2)**0.5
2)
def calculate_formula(a, b, c):
"""Calculate the result of the formula (a+b)/4 + (a-b)/2 - c/a + b/c.
Args:
a (float): The first parameter of the formula.
b (float): The second parameter of the formula.
c (float): The third parameter of the formula.
Returns:
float: The result of the formula.
"""
return (a + b) / 4 + (a - b) / 2 - c / a + b / c