from random import * def Main() : Questions = [] Answers = [] Counts = [] setup(Questions, Answers, Counts) limit = int(input("How many times should I ask a question to make sure you've got it?")) while numberOfQuestions(Counts) > 0 : qnNum = chooseQuestion(Counts) correct = askQuestion(Question[qnNum], Answer[qnNum]) if correct == "quit" : break elif correct : Counts[qnNum] = Counts[qnNum]+1 else : Counts[qnNum] = 0 if numberOfQuestions(Counts) == 0 : print("Well Done! You've got them all") else : print("Bye for now, you've still got some practicing to do") # Sets up the lists of questions Setup(Questions, Answers, Counts) : addQuestion("When are you allowed to pass another vehicle? When you are coming up to a blind corner or blind bend.", false, Questions, Answers, Counts) addQuestion("When are you allowed to pass another vehicle? When a vehicle has stopped at a pedestrian crossing.", false, Questions, Answers, Counts) addQuestion("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.", true, Questions, Answers, Counts) addQuestion("When are you allowed to pass another vehicle? When you are less than 10 meters away from a railway level crossing", false, Questions, Answers, Counts) addQuestion("Passengers in your vehicle are 15 years of over. Who is responsible for making sure they wear a safety belt? The passengers themselves", true, Questions, Answers, Counts) addQuestion("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" false, Questions, Answers, Counts) addQuestion("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", false, Questions, Answers, Counts) addQuestion("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 ", false, Questions, Answers, Counts) addQuestion("Which of your vehicle\'s light do you have on if you are drving in a fog? Park lights", false, Questions, Answers, Counts) addQuestion("Which of your vehicle's lights do you have on if you are drving in a fog? Headlights on high beam", false, Questions, Answers, Counts) Question("Which of your vehicle's light do you have on if you are drving in a fog? Hazard lights", false, Questions, Answers, Counts) addQuestion("Which of your vehicle's light do you have on if you are drving in a fog? Dipped headlights", true, Questions, Answers, Counts) addQuestion(question, answer, Questions, Answers, Counts) : Questions.extend(question) Answers.extend(answer) Counts.extend(0) # works out how many questions haven't reached the limit and still need to be asked numberOfQuestions(Counts, limit) : qnCount = 0 for (count in Counts) if count < limit : qnCount = qnCount+1 return qnCount # chooses a question at random until it finds one whose count is less than the limit chooseQuestion(Counts, limit): while true : index = randint(0, len(Counts)) if counts[index] < limit : return index #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" askQuestion (question, correctAnswer): print(question) answer = input("true or false? (or quit)") while true : if answer.lower().startswith('q') : return "quit" elif answer.lower().startswith('y') or answer.lower().startswith('t') : userAnswer = true break elif answer.lower().startswith('n') or answer.lower().startswith('f') : userAnswer = false break print("That wasn't a valid answer. Please try again") print(question) answer = input("true, false, yes, no, or quit (or first letter of those)") if userAnswer == correctAnswer : print("you got it right!") return true else print("No, that's wrong. The correct answer is " correctAnswer) return false