[Tutor] help understanding part of the tutorial...

Michael Janssen Janssen@rz.uni-frankfurt.de
Thu Jan 9 18:59:42 2003


On Thu, 9 Jan 2003, Gregor Lingl wrote:

> ... and how would you comment the following code?
>
>  >>> questions = [["What color is the daytime sky on a clear day?","blue"],
>            ["What is the answer to life, the universe and
> everything?","42"],
>            ["What is a three letter word for mouse trap?","cat"]]
>
>  >>> def check(q_and_a):
>        return q_and_a[1] == raw_input(q_and_a[0])
>
>  >>> for question in questions:
>        print check(question)
>
That's pretty (because the code is written to do something, not to make
everything step-by-step-by-step by inventing extra steps). what about:

questions = [
    ["What color is the daytime sky on a clear day?", "blue"],
    ["What is the answer to life, the universe and everything?","42"],
    ["What is a three letter word for mouse trap?", "cat"]]

for question, answere in questions:
    print (raw_input(question+" ") == answere)

----
More the behavior of the former code would be:
right = 0
wrong = 0
for question, answere in questions:
    if (raw_input(question+" ") == answere):
        print "this was expectet"
        right = right +1
    else:
        wrong = wrong +1
        print "%s! Why don't you answere '%s'?" \
              % ("No"*wrong, answere)


print "You got %s %% out of %s." %
(right*100/len(questions),len(questions)),
print "You are %s." % ["a loser", "bad", "good", "pythonic"][right]
----

A "check" function is very handy for a realistic approach, where more than
one answere can be correct or misspelling should gain another result than
no answere at all than something completly wrong.

For a realistic approach "questions" needs to carry a history of
wrong/correct attemps (to work especially on the difficult questions, or
to analyze the students main problems). "questions" should be organized in
levels or topics (and "higher" topics should be linked to topics, which
are necessary to understand them. This way the learner can be guided back,
in case s/he makes many mistakes).

aah 42? Let me see. It's 6 times 7.

Michael