Note that there are some explanatory texts on larger screens.

plurals
  1. POmy python code - for javascript?
    primarykey
    data
    text
    <p>I was wondering if someone could give me advice on this code. I have done it in python but I think I need to have it in javascript as it is for a website. I am new to programming so please be kind! </p> <p>Aims of the site:</p> <ul> <li>The user will have to answer 6 multiple choice questions. (Q1 has 7 possible answers but the others only have 2).</li> <li>Depending on their inputs they will receive an outcome (I have just put the outcomes as range(1,225) for now but there will be different outcomes depending on the input</li> <li>The outcomes and the possible input combinations are all fixed and will not change</li> </ul> <p>I am pretty sure I have not done it the best way as I don't have much experience, but it seems to work so far.</p> <p>Does the code look ok? Do you think I will be able to translate this into javascript easily enough? Should I have the table of outcomes/inputs fixed in some way so it doesn't need to be worked out by the computer every time or is it ok as it is?</p> <p>Any advice or help is very much appreciated indeed.</p> <pre><code>#list of possible inputs list = [[23,24,25,26,27,28,29],["male","female"],["true","false"],["true","false"], ["true","false"],["true","false"]] #make a list of outcomes outcome=[] for i in range(1,225): outcome.append(i) #make a table of all possible list input combinations r=[[]] for e in list: table = [] for item in e: for i in r: table.append(i+[item]) r = table #make a dictionary where the input is the key and outcome is the value adict = dict((str(r), outcome) for r, outcome in zip(r, outcome)) #dummy inputs as an example input1 = 27 input2 = "male" input3 = "true" input4="true" input5="true" input6="true" #put all the inputs into one string &amp; look up outcome in adict new_input = [] new_input.extend([input1,input2,input3,input4,input5,input6]) print adict.get(str(new_input)) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload