# L-12.5 MCS 260 Mon 14 Jul 2014 : questions
"""
The module questions generates questions,
evaluates the choice, and
keeps the tally of right and wrongs.
"""

import quand

def generate():
    """
    Returns a multiple choice question
    as a tuple (qst, ans), where qst is a number,
    and ans is a list of numbers with answers.
    """
    import random
    qst = random.randint(1, len(quand.QUESTIONS))
    ans = range(1, len(quand.ANSWERS[qst])+1)
    return (qst, ans)

def evaluate(ans, chc):
    """
    Evaluates choice chc to True or False
    where ans is a list of answers.
    """
    return (ans[chc-1] == 1)

def update_tally(tly, boolvar):
    """
    Updates tally of True or False answers
    where tly is a list of two elements and
    boolvar is True or False, returns the updated tally.
    """
    newtly = tly
    if boolvar:
        newtly[1] += 1
    else:
        newtly[0] += 1
    return newtly
