# L-19 MCS 260 Wed 10 Oct 2007 : 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\ \non input is the number q of the question\ \nand 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\ \nwhere 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\ \nwhere 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