i have been trying to do a theory test in python, and i want the code to take a random question from the file that i created and ask the user for the answer.
i made two files, one contains the questions and the other one is for the answers.
value = 0
q1 = open('questions.txt','r')
q1_question = q1.readlines()[0]
print(q1_question)
a1 = open('answers.txt','r')
a1_answer = a1.readlines()[0]
answer1 = input("Enter your answer: ").lower()
if answer1 != a1_answer:
value = value + 1
the value is for the wrong answers, now, this is just the first question, my goal is that the user get a random question and would need to type the correct answer, and in the end the user will be shown how much questions he got wrong.
answers.text: b
questions.text: What should a driver do after parking his vehicle?| A) Turn on all the winkers. B) Ensure that the vehicle remains immobile and cannot move. C) Place a warning triangle. Wearing a seat belt as required:| A) Keeps the driver in an upright sitting position. B) Reduces the extent of injury during an accident. C) Keeps the driver alert. Is it permitted to re- fuel a vehicle while its motor is running?| A) Absolutely not. B) Yes, in case of self-fueling. C) Yes, when the vehicle stands next to a fire extinguishing station. It is prohibited to stop, park or stand a vehicle on or before a pedestrian crossing, within a distance of:| A) 20 meters from the crossing. B) 12 meters from the crossing. C) 24 meters from the crossing. Which driver related ability is impaired during fog?| A) Vision. B) Vehicle acceleration. C) Steering. Is it permitted to drive passengers for hire in a private passenger car?| A) Only during a public transportation strike. B) No. C) Only in inter-urban rides.