2

I am trying to code the following:

there will be six inputs, say 1,2,3,4,5,6

inputs 2-6 have two possible options (say yes and no)

input 1 has seven possible options (say a-g)

depending on which inputs are selected, a specific output will be generated.

So if you had - a, yes, yes, no, no, no - it would generate outcome 'x'

I have managed to create a list with all the possible input combinations (using python):

list = [[23,24,25,26,27,28,29],["male","female"],["true","false"],["true","false"],["true","false"],["true","false"]]

r=[[]]
for e in list:
    table = []
    for item in e:
            for i in r:
                table.append(i+[item])
    r = table

print r

My next stage is to allocate an outcome to each of these options. I guess the best way to do this is just append the output to each list item so that

for e in index, if e[0]-e[5] matches the input then print out e[6]

Is this an ok way to do it?

EDIT

Just to make it clearer I just thought I'd explain what I am actually trying to do. It's a free tool for doctors (I'm a doc - it's not for commercial purposes just to improve patient care).

It is a way of calculating risk for the patient, so there will be five questions the doc will input - e.g. male/female etc and depending on their inputs it will produce the outcome as a % risk for the patient. We are using years of previous patient outcome data to produce the table of outcome.

4

1 回答 1

2

您可以将输入 2-6 视为 5 位(5 个布尔值),将输入 1 视为 3 个高位(编码 7 个值)。然后从 0 到 223 循环,按照上面的方案对数字进行解码,生成所有可能的组合。

于 2012-06-06T15:01:34.207 回答