[Tutor] help with augumented assignment y += 1
Emile van Sebille
emile at fenx.com
Wed Jul 30 21:04:48 CEST 2008
Norman Khine wrote:
> Hi,
> Appologies, there was a typo, in that the first line is:
>
> ['1'] ['a1', 'a2', 'a2', 'a2'] [1, 1, 2, 4]
Yes -- that helps.
So, working from your xml samples, by doing something like:
responses = [ [a,b,c] for a,b,c in responseAnalysisGenerator ]
you can end up with responses and survey that look like:
responses = [
[['1'],['a1', 'a2'],[1, [2,3]]],
[['5'],['a1', 'a2'],[1, 2]],
[['3'],['a1', 'a2'],[3, 4]]
]
survey = [{'question': 'a1',
'options': [[u'Yes',
u'No',
u"Don't know"]],
'title': u"Is an augumented assignment such as \
'x = x + 1' the same as x += 1?"},
{'question': 'a2',
'options': [[u"'x = (x * y) + 1'",
u"'x = x * (y + 1)",
u"'x = (y + 1) * x'",
u'All of the above']],
'title': u"The statement 'x *= y + 1' is equivalent to:"}]
Now the questions evolves to extracting the appropriate formatted output
from these two structures. This can take place in many ways and is
directly a function of the range of questions you'd want to answer. In
addition to the totals by question, one of your output formats appeared
to be a restatement by user of the survey. This suggests a class
structure where you initialize the class with something like:
myAnalyzer = SurveyAnalyzer(survey,responses)
and let it respond to queries like:
sampleRecap = myAnalyzer.recap()
sampleRecap = myAnalyzer.userResponse('3')
Does this help?
Emile
More information about the Tutor
mailing list