Python desde la documentación

Genera una función de Python dada su docstring

Puedes consultar un modelo directamente y probar los resultados que se muestran cuando usas valores de parámetros diferentes con la consola de Cloud o con una llamada directa a la API de Vertex AI.

Mensaje Formato libre


from collections import namedtuple
from math import sqrt


# A point has an x and a y coordinate
Point = namedtuple('Point', 'x y')
# A triangle is defined by three points
Triangle = namedtuple('Triangle', 'a b c')


def distance(p, q):
"""Returns the distance between the provided pair of points"""
return sqrt((p.x - q.x)**2 + (p.y - q.y)**2)


def perimeter(triangle):
"""Returns the perimeter of the provided triangle"""
return distance(triangle.a, triangle.b) + distance(triangle.b, triangle.c) + distance(triangle.c, triangle.a)


def area(triangle):
"""Returns the area of the provided triangle using Heron's formula"""

Escribe el cuerpo de la función del área, siguiendo su docstring.

Respuesta


from collections import namedtuple
from math import sqrt


# A point has an x and a y coordinate
Point = namedtuple('Point', 'x y')
# A triangle is defined by three points
Triangle = namedtuple('Triangle', 'a b c')


def distance(p, q):
"""Returns the distance between the provided pair of points"""
return sqrt((p.x - q.x)**2 + (p.y - q.y)**2)


def perimeter(triangle):
"""Returns the perimeter of the provided triangle"""
return distance(triangle.a, triangle.b) + distance(triangle.b, triangle.c) + distance(triangle.c, triangle.a)


def area(triangle):
"""Returns the area of the provided triangle using Heron's formula"""
s = perimeter(triangle) / 2
return sqrt(s * (s - distance(triangle.a, triangle.b)) * (s - distance(triangle.b, triangle.c)) * (s - distance(triangle.c, triangle.a)))
Modelo: gemini-1.5-flash-001
Temperatura: 1
Cantidad máxima de tokens de salida: 8192
K superior 40
P superior 0.95