函数,求面积,海伦公式

img

img


def heron_formula(a, b, c):
    p = (a + b + c) / 2
    S = (p * (p - a) * (p - b) * (p - c)) ** 0.5
    return S


def check_rule(a, b, c):
    if ((a + b) > c) + (abs(a - b) < c) == 2:
        return True
    return False


if __name__ == '__main__':
    u_input = str(input("Input:"))
    a, b, c = map(lambda x: float(x), u_input.split(" "))
    if check_rule(a, b, c):
        S = heron_formula(a, b, c)
        print(f"面积为:{S}")
    else:
        print("三条边不符合规范!")



import math

x = eval(input().replace(' ', ','))
a, b, c = map(lambda x: x, x)
if b + c > a:
    p = (a + b + c) / 2
    s = math.sqrt(p * (p - a) * (p - b) * (p - c))
    print(s)

有帮助请点击右上角的采纳,有问题继续交流,你的采纳是对我回答的最大的肯定和动力

img