We use lists of lines for other question attributes (e.g. setup,
teardown, answer). Be consistent with multi-line prompts.
The handling is in Question.format_prompt() for easy access by any
consumer. The `newline` option will make it easy to support
non-terminal output formats (e.g. `newline='<br/>'` for HTML).
if args.questions:
for i,q in enumerate(stack):
print('Question {}:'.format(i))
- print(q.prompt)
+ print(q.format_prompt())
print()
return
ui = _cli.CommandLineInterface(quiz=quiz, answers=answers, stack=stack)
def check(self, answer):
return answer == self.answer
+ def format_prompt(self, newline='\n'):
+ if isinstance(self.prompt, str):
+ return self.prompt
+ return newline.join(self.prompt)
+
class NormalizedStringQuestion (Question):
def normalize(self, string):
question = self.get_question()
if not question:
break
- print(question.prompt)
+ print(question.format_prompt())
if question.multiline:
answers = []
while True:
return
if a in ['?', 'help']:
print()
- print(question.prompt)
+ print(question.format_prompt())
print(question.help)
continue
if question.multiline:
def display_result(self, question):
answers = self.answers.get(question.id, [])
- print('question: {}'.format(question.prompt))
+ print('question:')
+ print(' {}'.format(question.format_prompt(newline='\n ')))
la = len(answers)
lc = len([a for a in answers if a['correct']])
print('answers: {}/{} ({:.2f})'.format(lc, la, float(lc)/la))