A quiz app marks answers that players type in. Comparing them exactly is too strict: "Paris." and "paris" mean the same thing, and so do "Blue Whale" and "blue whale". So before comparing, both the player's answer and the correct answer are normalised.
A normalised string:
- turned into a space, so "well-known" and "well known" match;. , ! ? ; : ' "Task: write two functions.
normalise(text) returns the normalised version of text.exact_match_rate(predictions, answers) takes two lists of the same length — the player's answers and the correct answers, in matching order — and returns the fraction of positions where the two normalised strings are identical, rounded with round(rate, 4). If the lists are empty, return 0.0."4" and "four" still don't match: normalising tidies up the typing, it doesn't understand meaning.