Project 8 of 20, for Caitlin
Quiz App
Caitlin's Thursday quiz night, with rounds on music, food and games: questions in a JSON file, shuffled every week, asked, marked and scored, mostly with lists made out of other lists.
Sign up free to open itLog in
Act 2 needs a free account, so your work is saved as you go. Act 1 is open to everyone.
The brief
- CaitlinI'm running the class quiz on Thursday, and my question sheet's got a coffee ring over half the answers.
- CaitlinI want the questions in a file, in a different order every week, with marking nobody can argue with.
- CaitlinLast time Yahya argued that piano and the piano were different answers, and he won the argument but not the quiz.
- PaulOnce they're loaded it's mostly shuffling and marking, and nearly all of that is lists made out of other lists.
Caitlin's questions are in questions.json: a list of dictionaries, each with a round, a question, an answer, and sometimes also, a list of other answers she'll accept. Write quiz.py, with a comprehension at the heart of each of the first four:
round_names(questions)returns the different rounds, in alphabetical order.round_sizes(questions)returns a dictionary of each round's name and how many questions it has, in the same order.in_round(questions, name)returns the questions in that round, in the order they're in the book. Capitals, and spaces at the ends ofname, don't matter.answer_sheet(questions, answers)returns a line for each question, numbered from 1:1. time: right, or2. the piano: you said keyboard.is_right(given, question)isTrueifgivenis the answer or one of itsalso, ignoring capitals and spaces at the ends.score(questions, answers)says how many are right.main()prints the rounds, then asksWhich round?until the answer is one of them; anything else getsNo round called Sport.It shuffles that round's questions withrandom.shuffle, prints each one numbered and reads the answer after>, then printsAnswers:, the answer sheet, andScore: 3 out of 4.
Rounds: Food (4), Games (4), Local (4), Music (4) Which round? music 1. What does a metronome keep? > time 2. Which instrument has 88 keys? > keyboard 3. How many strings does a standard guitar have? > six 4. What do you call a group of four musicians? > Quartet Answers: 1. time: right 2. the piano: you said keyboard 3. 6: right 4. a quartet: right Score: 3 out of 4
What you learn
What's in it
- Lists and dictionaries in a file
- Written as JSON
- The question book
- A list made from a list
- A list in one line
- Keeping only some
- The long answers
- Choosing what to write
- Two places for an if
- Sets and dictionaries in one line
- The same key twice
- A different order every week
- What shuffle hands back
- How Paul would do it
- Fix Yahya's version
- Make the quiz
- Ship it