# L-12.5 MCS 260 Mon 14 Jul 2014 : dialogue
"""
The module dialogue defines the dialogue
with the user: show questions, prompt for
a choice, show the outcome and tally.
"""

import quand

def show_question(qst, ans):
    """
    Displays the questions and the answers
    on input is the number qst of the question
    and the list ans of answers.
    """
    print quand.QUESTIONS[qst]
    choice = 1
    for answer in ans:
        prt = '%d' % choice + '. '
        prt = prt + quand.ANSWERS[qst][answer]
        print prt
        choice = choice + 1

def prompt_choice(num):
    """
    Asks the user for a choice
    where num is the number of choices.
    """
    msg = 'type a number between 1'
    msg = msg + ' and %d : ' % num
    while True:
        selection = raw_input(msg)
        sel = int(selection)
        if sel > 0 and sel <= num:
            break
        print 'please try again'
    return sel

def show_outcome(boolvar):
    """
    Reports outcome to user
    where boolvar is True or False.
    """
    if boolvar:
        print 'this is the correct answer'
    else:
        print 'wrong, please try again'

def show_tally(tly):
    """
    Shows final tally, tly is list.
    """
    cnt = '#correct : %d' % tly[1]
    cnt += ' #wrong : %d' % tly[0]
    frm = 100.0*tly[1]/sum(tly)
    cnt += ' -> %.2f%%' % frm
    print cnt
