Documentazione di Python

Genera una funzione Python in base alla relativa docstring

Puoi eseguire query direttamente su un modello e testare i risultati restituiti quando utilizzi i diversi valori dei parametri con la console Cloud o chiamando il metodo l'API Vertex AI in modo diretto.

Prompt In formato libero


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"""

Scrivi il corpo della funzione area, seguendo la relativa docstring.

Risposta


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)))
Modello: gemini-1.5-flash-001
Temperatura: 1
Numero massimo di token di output: 8192
TopK: 40
TopP: 0,95