求各位大佬看看代码该怎么改
老是报错,请问问题出在哪 代码如下:import math
a=eval(input())
b=eval(input())
c=eval(input())
p=(a+b+c)/2
s=math.sqrt(p(p-a)(p-b)(p-c))
x=float(s)
if a+b>c and a+c>b and c+b>a:
print("{}".format(x))
else:
print("不能构成三角形")
import math
a=eval(input())
b=eval(input())
c=eval(input())
p=(a+b+c)/2
if a+b>c and a+c>b and c+b>a:
s = math.sqrt(p * (p - a) * (p - b) * (p - c))
print("{}".format(s))
else:
print("不能构成三角形")
代码可不能省略掉乘法符号, 当不能构成三角形的时候,根号下的值可能小于0, 所以应该把s放到if分支下面去 这一句
s=math.sqrt(p(p-a)(p-b)(p-c))
改为
s=math.sqrt(p * (p-a) * (p-b) * (p-c)) jackz007 发表于 2021-12-4 20:37
这一句
改为
谢了兄弟,是我太粗心了 本帖最后由 傻眼貓咪 于 2021-12-4 21:06 编辑
题目要求只保留小数点后一位import math
def area(a, b, c):
s = (a+b+c)/2
return math.sqrt(s*(s-a)*(s-b)*(s-c))
def isTriangle(a, b, c): return (a+b > c) and (a+c > b) and (b+c > b)
a, b, c =
print(f"{area(a, b, c):.1f}" if isTriangle(a, b, c) else "不能构成三角形")
页:
[1]