如何为以下代码创建决策表

2024-10-01 04:44:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图为一个三角形分类程序创建一个决策表,代码如下所示。更新

def tritype(a, b, c):
    if ((a ^ 2 + b ^ 2) == c^2):
        return "Right Triangle"
    if ((a + b) == c):
        return "Isosceles Triangle"
    if (a + b > c):
        return "Scalene Triangle"
    if ((a == b) and (b == c) and (a == c)):
        return "Equilateral Triangle"
    if ((a < 1) or (b < 1) or (c < 1)):
        return "Negative Lenght Error"
    else:
        return "Invalid Triangle Error"

这是我到目前为止的情况

第1步:列出所有条件和效果:

^{pr2}$

我不确定如何将上述信息放入表中。在


Tags: orand代码rightreturnifdeferror
1条回答
网友
1楼 · 发布于 2024-10-01 04:44:42

要生成与上面显示的表类似的表,只需使用\t作为间距和一些简单的打印命令。在

desc_table = [["C1", "A2 + B2 = C2"], ["C2", "A + B > C"]]

for entry in desc_table:
   print(entry[0]+'\t'+entry[1])

要在决策表数组中搜索条目,只需迭代所有元素。在

^{pr2}$

这是一个相当简单的解决办法,但我认为就你的目的而言,这是完全足够的。在

相关问题 更多 >