Python Program example
An Application for studying for the Driver's Licence Theory Test.
Task:
Write a program for an application that will help the user study for the theory test for their driver's licence. The application will repeatedly ask the user questions and keep track of how many times they have answered each question correctly. It will choose questions from its question bank at random, and will ask questions multiple times until the user has learned the answer correctly. It won't ask any question once the user has answered it correctly a specified number of times. The user can specify this limit at start up. The program will keep track of how many times the user has answered each question correctly. The count for a question starts again whenever the user gets the question wrong. Many of the questions in the test are multiple choice questions. You can choose how your program will ask them:Option 1.
Ask the question, and present all of the possible answers. The user has to type "a", "b", etc. to answer the question. This means that you have to store the four (or more) possible answers along with each question, and also store which of the choices is correct.For example:
- You are driving in a 100km/h zone and you see an accident sign, what speed should you slow down to?
- 70km/hr
- 50km/hr
- 30km/hr
- 20km/hr
Option 2.
Turn each question into a collection of yes/no questions, and treat them as separate questions. The user has to type yes or no to answer them. This means that you only have to store true/false with each question.For example:
- You are driving in a 100km/h zone and you see an accident sign, what speed should you slow down to? 50km/hr?
true or false:
Other considerations
Your program should allow the user to quit at any time by typing "quit" or "q" to one of the questions. You can give your program a GUI if you want, but it is OK to use a text interface. If you use a text interface, you won't be able to use the questions that involve a diagram. Note, you do not have to use questions for the driving test. You can use a set of questions for any topic that you would want to study for.Design (true/false question option):
Data/Information * Questions: a list of strings. Each string is a question and a possible answer. * Answers: a list of correct answers to the question (true/false) * Counts: a list of the number of times each question has been answered correctly. * limit: number of times a questions must be answered correctly to not be asked any more. Main module: parameters: none returns: nothing Create empty lists in Questions, Answers, and Counts Set up the questions (call setup module, passing Questions, Answers, and Counts) Ask user for the number of times to repeat a question --> Limit While there are still questions to ask (call numberOfQuestionsLeft module passing Counts and limit) Choose a question number (call chooseQuestion module passing Counts and limit) --> qnNum 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 qnNum'th count, otherwise reset qnNum'th count to 0 Display completion message, depending on whether they completed all questions or not Setup module: function: Sets up the lists of questions Parameters: Questions, Answers, Counts, returns: nothing Call addQuestion module, passing question and answer, Questions, Answers, Counts, (repeat this for every question) addQuestion module: function: adds a question and its answer to the lists and initialises its count parameters: question (String), answer (true/false), Questions, Answers, Counts, returns: nothing add question to list of Questions add answer to list of Answers add 0 to list of Counts numberOfQuestionsLeft module: function: works out how many questions haven't reached the limit and still need to be asked parameters: Counts (list of numbers), limit (number), returns number of questions left set numLeftto 0 for each element of Counts if the element is less than the limit, add one to numLeft. Return the numLeft chooseQuestion module: function: chooses a question at random until it finds one whose count is less than the limit parameters: Counts (list of numbers), limit (number) returns: index of a question repeat choose an index of Counts at random ? qnNum until the qnNum'th count in Counts is less than the limit. Return qnNum 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 (String), answer (boolean) returns: whether answer was correct or not, or if the user wants to quit. Print out the question, and ask for true/false -> answer repeat If answer is 'q' or "quit" then return the value "quit" If answer is valid, check against correct answer print out an appropriate message return true or false for success or failure. If answer is invalid, repeat the question and say what the valid answers are.
Sample Questions
When are you allowed to pass another vehicle?- When you are coming up to a blind corner or blind bend.
- When a vehicle has stopped at a pedestrian crossing.
- * When you can see at least 100 meters of clear road in front of you once you have finished passing.
- When you are less than 10 meters away from a railway level crossing
- * The passengers themselves
- The parents of the passengers
- You as the driver of the vehicle
- Other passengers in your vehicle
- Park lights
- Headlights on high beam
- Hazard lights
- * Dipped headlights
- Passengers in your vehicle are 15 years of over. Who is responsible for making sure they wear a safety belt? Other passengers in your vehicle?
- Passengers in your vehicle are 15 years of over. Who is responsible for making sure they wear a safety belt? The parents of the passengers?
- Passengers in your vehicle are 15 years of over. Who is responsible for making sure they wear a safety belt? The passengers themselves
- Passengers in your vehicle are 15 years of over. Who is responsible for making sure they wear a safety belt? You as the driver of the vehicle?
- When are you allowed to pass another vehicle? When a vehicle has stopped at a pedestrian crossing.
- When are you allowed to pass another vehicle? When you are less than 10 meters away from a railway level crossing
- When are you allowed to pass another vehicle? When you can see at least 100 meters of clear road in front of you once you have finished passing.
- Which of your vehicle's lights do you have on if you are driving in a fog? Dipped headlights?
- Which of your vehicle's lights do you have on if you are driving in a fog? Hazard lights?
- Which of your vehicle's lights do you have on if you are driving in a fog? Headlights on high beam?
- Which of your vehicle\'s lights do you have on if you are driving in a fog? Park lights?
- When are you allowed to pass another vehicle? When you are coming up to a blind corner or blind bend.
A possible answer (not checked yet)
- QuizProgram.py.txt: QuizProgram.py.txt
- QuizProgramBuggy.py.txt: QuizProgram.py.txt (with syntax errors)
- QuizProgramSimpleGlobals.py.txt: Quiz Program using Globals (no parameters), simpified structure, and little robustness