直角三角形
a, b, c = int(input()), int(input()), int(input())n = (a+b>c) and (a+c>b) and (b+c>a)
if n == True:
if a*a + b*b == c*c and a*a + c*c == b*b and b*b + c*c == a*a:
print("YES")
else:
print("NO")
else:
print("NO")
#最后有的结果是错的,大佬这个怎么解决 a, b, c = int(input()), int(input()), int(input())
n = (((a+b>c) and (a+c>b) and (b+c>a)) and#判断是否是三角形
((a*a + b*b == c*c or a*a + c*c == b*b or b*b + c*c == a*a)) and #判断是否是直角三角形
(a > 0) and (b > 0) and (c > 0)) #判断特殊输入
if n:
print("YES")
else:
print("NO")
本帖最后由 zhangjinxuan 于 2022-11-25 14:56 编辑
直角三角形满足的应该是两条短边的平方和等于长边平方:
a, b, c = int(input()), int(input()), int(input())
n = (a+b>c) and (a+c>b) and (b+c>a)
if n == True:
x, y, z = sorted()
if x * x + y * y == z * z:
print("YES")
else:
print("NO")
else:
print("NO")
zhangjinxuan 发表于 2022-11-25 13:55
直角三角形满足的应该是两条短边的平方和等于长边平方和:
还有一组的元素不匹配,该怎么解决呢? 本帖最后由 Ftxz1034 于 2022-11-25 14:10 编辑
第四行的and应该改为or,满足三的条件中的任何一个就是直角三角形了
还有一个问题你没考虑用户输入0或者负数的情况 本帖最后由 Ftxz1034 于 2022-11-25 14:57 编辑
print('请输入三角形的三边,并以“空格”分隔')
x = input()
(a,b,c) = x.split()
a = int(a)
b = int(b)
c = int(c)
n = (a+b>c) and (a+c>b) and (b+c>a)
m = a > 0 and b > 0 and c > 0
if n and m:
if a*a + b*b == c*c or a*a + c*c == b*b or b*b + c*c == a*a:
print("YES")
else:
print("NO")
else:
print("数字输入有误!")
iwillsowill 发表于 2022-11-25 14:02
还有一组的元素不匹配,该怎么解决呢?
哪一组?确认不会输入小数、负数、等非法数的情况? 如果a是30,b是90,c是60,那就不满足你a+c>b了 zhangjinxuan 发表于 2022-11-25 14:55
哪一组?确认不会输入小数、负数、等非法数的情况?
数字为5.5, 4.5,6.5
iwillsowill 发表于 2022-11-28 18:21
数字为5.5, 4.5,6.5
啊这{:10_282:}
小数怎么能用 int ???
a, b, c = float(input()), float(input()), float(input())
n = (a+b>c) and (a+c>b) and (b+c>a)
if n == True:
x, y, z = sorted()
if x * x + y * y == z * z:
print("YES")
else:
print("NO")
else:
print("NO")
tommyyu 发表于 2022-11-25 14:44
将int改为eval就可以了
iwillsowill 发表于 2022-11-28 18:25
将int改为eval就可以了
这个可以吗?
a, b, c = float(input()), float(input()), float(input())
n = (a+b>c) and (a+c>b) and (b+c>a)
if n == True:
x, y, z = sorted()
if x * x + y * y == z * z:
print("YES")
else:
print("NO")
else:
print("NO")
可以的话,给个最佳,啊,我有点晕了{:10_291:} zhangjinxuan 发表于 2022-11-29 10:08
这个可以吗?
可以的话,给个最佳,啊,我有点晕了
抱歉手滑了给到上面了{:5_100:} iwillsowill 发表于 2022-11-30 12:23
抱歉手滑了给到上面了
没事{:10_282:}(心中有点不愉快)
页:
[1]