Editor

Quiz Marker With Feedback

#627 · Strings · Intermediate · Mini-project · 155 XP · about 50 min

A teacher sets short-answer quizzes and wants them marked automatically, without failing a student for typing Paris. instead of paris. The answer key is a dictionary that maps each question number to a pair (accepted, points): the list of answers that count as right, and the points the question is worth. A student's answers are a dictionary from question number to the text they typed; a question they skipped is missing.

Parts

  • Part 1 normalize(answer): the answer in a standard form: lower case, without any ., ! or ? at its end (spaces after them do not count), with no spaces at either end, and with every run of spaces inside it turned into one space.
  • Part 2 is_correct(given, accepted): True if the normalized given answer equals the normalized form of any answer in accepted.
  • Part 3 score_quiz(answers, key): a pair (earned, possible): the points for the questions answered correctly, and the points of every question in the key.
  • Part 4 feedback(earned, possible): a message such as '67%: Getting there'. The percentage is round(100 * earned / possible), and the words are 'Excellent work' from 90, 'Good job' from 70, 'Getting there' from 50 and 'Keep practicing' below 50. possible is always more than 0.
  • Part 5 review_list(answers, key): the numbers of the questions the student got wrong or skipped, from smallest to largest.

Examples

key = {1: (['Paris'], 2), 2: (['4', 'four'], 1), 3: (['Mercury'], 3)}
answers = {1: 'paris', 2: 'Four!', 3: 'Venus'}
normalize('  New   York ')       # returns 'new york'
is_correct('Four!', ['4', 'four'])  # returns True
score_quiz(answers, key)        # returns (3, 6)
feedback(3, 6)                  # returns '50%: Getting there'
review_list(answers, key)       # returns [3]

Constraints

  • A quiz has at most 100 questions, numbered with whole numbers, and every answer is a string.

Fastest solvers

Leaderboard

First solves only, ranked by stars and then time.