Quiz program
Task:
Write a program for an application that let the user host a quiz game. The application will have a collection of questions with short answers. The program should ask the user how many question they want for their game. It will then ask that many questions in random order. When the user types in an answer, it will check the answer against the correct answer and keep track of the number of questions they got right. It will never ask the same question twice. When all the questions have been asked, or the user has quit (by typing "quit" as an answer), the program will print the score and the total number of questions asked.
Your program should have an appropriate modular structure.
Assessment criteria:
put this into the "pizza" framework.
possible extension ideas
(not to give to students)
- personalised welcome and score.
- better end message depending on the result
- read questions and answers from a file
- partial matching of answer to cope with spelling errors
- difficulty levels - choose a difficulty level and select the right questions
- different genres of questions
- nicer user interface
Sample design
note, need two designs
- an achieved plan that has no parameters and no robustness
- a merit plan that improves on the previous plan with parameters and some design for robust input handling. Students could start with the simple plan, if they can implement that, they can then revise and extend their program to implement the better plan
---- achieved version:
Data/Information
* Questions: a list of strings. Each string is a question
* Answers: a list of correct answers to the question
* number of questions to ask
* score (number of correct answers so far)
* number of questions asked so far.
Main module
parameters: none
returns: nothing
Create empty lists in Questions, and Answers
Set up the questions (call setup module)
Ask user for the number of questions to ask
While there are still questions to ask
Choose a random question number --> qnNum
increment the number of questions asked
Ask question (call askQuestion module, passing question and answer) --> result
delete the question and answer from the lists
If result was that the user wants to quit, then quit,
if result was correct, then increment score
Display ending message reporting the score and how many questions were asked
Setup module
function: Sets up the lists of questions
Parameters: none
returns: nothing
add a question to Questions
add the corresponding answer to Answers
(repeat this for every question)
askQuestion module
function: asks the user a question, and returns true or false depending on whether they answered correctly.
If the user answered with 'q', then it should return "quit"
parameters: none
returns: whether answer was correct or not, or if the user wants to quit.
Print out the question, and ask for answer
repeat
If answer is "quit" then return the value "quit"
If answer is the correct answer
return true
If answer is not correct
return false
----More advanced version (should be for merit)
Data/Information
* Questions: a list of strings. Each string is a question
* Answers: a list of correct answers to the question
* number of questions to ask
* score (number of correct answers so far)
* number of questions asked so far.
Main module
parameters: none
returns: nothing
Create empty lists in Questions, and Answers
Set up the questions (call setup module, passing Questions and Answers)
Ask user for the number of questions to ask (checking validity and asking again if invalid)
While there are still questions to ask
Choose a random question number --> qnNum
Increment the number of questions asked
Ask question (call askQuestion module, passing question and answer) --> result
If result was that the user wants to quit, then quit,
if result was correct, then increment score
Display ending message reporting the score and how many questions were asked
Setup module
function: Sets up the lists of questions
Parameters: Questions, Answers (lists of strings)
returns: nothing
add a question to Questions
add the corresponding answer to Answers
(repeat this for every question)
askQuestion module
function: asks the user a question, and returns true or false depending on whether they answered correctly.
If the user answered with 'q', then it should return "quit"
parameters: question, answer (both strings)
returns: whether answer was correct or not, or if the user wants to quit.
Print out the question, and ask for answer
repeat
If answer is "quit" then return the value "quit"
If answer is the correct answer (dealing with upper and lower case)
return true
If answer is not correct
return false
Marking guide
- QuizNightWithQuestions.py.txt: QuizNight program with the addition of asking for the number of questions, and better reporting of the final score