fromcollectionsimportnamedtuplefrommathimportsqrt# A point has an x and a y coordinatePoint=namedtuple('Point', 'xy')# A triangle is defined by three pointsTriangle=namedtuple('Triangle', 'abc')defdistance(p,q):
"""Returnsthedistancebetweentheprovidedpairofpoints"""
returnsqrt((p.x-q.x)**2+(p.y-q.y)**2)defperimeter(triangle):
"""Returnstheperimeteroftheprovidedtriangle"""
returndistance(triangle.a,triangle.b)+distance(triangle.b,triangle.c)+distance(triangle.c,triangle.a)defarea(triangle):
"""ReturnstheareaoftheprovidedtriangleusingHeron'sformula"""
ドキュメント コメントに従って area 関数の本体を記述します。
レスポンス
fromcollectionsimportnamedtuplefrommathimportsqrt# A point has an x and a y coordinatePoint=namedtuple('Point', 'xy')# A triangle is defined by three pointsTriangle=namedtuple('Triangle', 'abc')defdistance(p,q):
"""Returnsthedistancebetweentheprovidedpairofpoints"""
returnsqrt((p.x-q.x)**2+(p.y-q.y)**2)defperimeter(triangle):
"""Returnstheperimeteroftheprovidedtriangle"""
returndistance(triangle.a,triangle.b)+distance(triangle.b,triangle.c)+distance(triangle.c,triangle.a)defarea(triangle):
"""ReturnstheareaoftheprovidedtriangleusingHeron'sformula"""
s=perimeter(triangle)/2returnsqrt(s*(s-distance(triangle.a,triangle.b))*(s-distance(triangle.b,triangle.c))*(s-distance(triangle.c,triangle.a)))
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2024-11-21 UTC。"],[],[]]