# L-22 MCS 260 Wed 3 Mar 2010 : 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(q,L): """ Displays the questions and the answers on input is the number q of the question and the list L of answers. """ print quand.questions[q] choice = 1 for answer in L: p = '%d' % choice + '. ' p = p + quand.answers[q][answer] print p choice = choice + 1 def prompt_choice(n): """ Asks the user for a choice where n is the number of choices. """ m = 'type a number between 1' m = m + ' and %d : ' % n while True: c = raw_input(m) if int(c) > 0 and int(c) <= n: break print 'please try again' return int(c) def show_outcome(b): """ Reports outcome to user where b is True or False. """ if b: print 'this is the correct answer' else: print 'wrong, please try again' def show_tally(t): """ Shows final tally, t is list. """ s = '#correct : %d' % t[1] s += ' #wrong : %d' % t[0] f = 100.0*t[1]/sum(t) s += ' -> %.2f%%' % f print s