iwillsowill 发表于 2022-11-25 13:47:43

直角三角形

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")
#最后有的结果是错的,大佬这个怎么解决

tommyyu 发表于 2022-11-25 13:47:44

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 13:55:39

本帖最后由 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")

iwillsowill 发表于 2022-11-25 14:02:09

zhangjinxuan 发表于 2022-11-25 13:55
直角三角形满足的应该是两条短边的平方和等于长边平方和:

还有一组的元素不匹配,该怎么解决呢?

Ftxz1034 发表于 2022-11-25 14:08:51

本帖最后由 Ftxz1034 于 2022-11-25 14:10 编辑

第四行的and应该改为or,满足三的条件中的任何一个就是直角三角形了
还有一个问题你没考虑用户输入0或者负数的情况

Ftxz1034 发表于 2022-11-25 14:54:56

本帖最后由 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("数字输入有误!")

zhangjinxuan 发表于 2022-11-25 14:55:14

iwillsowill 发表于 2022-11-25 14:02
还有一组的元素不匹配,该怎么解决呢?

哪一组?确认不会输入小数、负数、等非法数的情况?

莫忘乐乎 发表于 2022-11-25 16:47:46

如果a是30,b是90,c是60,那就不满足你a+c>b了

iwillsowill 发表于 2022-11-28 18:21:30

zhangjinxuan 发表于 2022-11-25 14:55
哪一组?确认不会输入小数、负数、等非法数的情况?

数字为5.5, 4.5,6.5

zhangjinxuan 发表于 2022-11-28 18:22:32

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

iwillsowill 发表于 2022-11-28 18:25:06

tommyyu 发表于 2022-11-25 14:44


将int改为eval就可以了

zhangjinxuan 发表于 2022-11-29 10:08:56

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:}

iwillsowill 发表于 2022-11-30 12:23:04

zhangjinxuan 发表于 2022-11-29 10:08
这个可以吗?

可以的话,给个最佳,啊,我有点晕了

抱歉手滑了给到上面了{:5_100:}

zhangjinxuan 发表于 2022-11-30 12:47:42

iwillsowill 发表于 2022-11-30 12:23
抱歉手滑了给到上面了

没事{:10_282:}(心中有点不愉快)
页: [1]
查看完整版本: 直角三角形