简体   繁体   中英

How to create a decision table for the following code

I am attempting to create a decision table for a Triangle Classification Program, code shown below. UPDATE

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"

Here is what I have so far

Step 1: List all conditions and effects:

C1  A2 + B2 = C2
C2  A + B > C
C3  A = C
C4  A  B = C
C5  A || B || C < 1
C6  A + B < C
E1  “Invalid Negative Length Error”
E2  “Invalid Triangle Error”
E3  “Right Triangle”
E4  “Isosceles Triangle”
E5  “Equilateral Triangle”
E6  “Scalene Triangle”

I'm unsure how to put the above information into the table itself.

To generate a table similar to the one displayed above you simply need to use \\t for spacing and some simple print commands.

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

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

To search for entries in your decision table array simply iterate over all the elements.

[entry for entry in desc_table if entry[0]=="C1"][0]

This is a fairly simple solution, but I think for your purpose it is totally sufficient.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM