Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- #list of questions asked by the computer, you can add your own but you have to change the answers then
- questions = [
- "Rainfall has been detected. Do you change your speed? [87 km/h]","A 'Sharp Turns' sign has been identified. Should you change your speed? [103 km/h]",
- "The vehicle in front of me suddenly brakes. There is no avoiding a collision. What to do?",
- "A vehicle in front of us has been identified as 'bicycle' [8 km/h]. What to do?",
- "The fuel level is less than 1/3, should we change the route?",
- "A collision was detected on the route at a distance of 10km. Modify the route?",
- ]
- #list of answers in order of questions asked, you can add your
- answers = [
- [ "1) Increase speed", "2) Decrease speed", "3) Don't change speed"],
- [ "1) Increase speed", "2) Decrease speed", "3) Don't change speed"],
- [ "1) Change lane to the left", "2) Pull over", "3) Brake without changing lane"], [ "1) Change to the left lane", "2) Overtake and return to the right lane", "3) No, keep going"],
- [ "1) Look for a station in the area up to 30km", "2) Look for a station in the area up to 50km", "3) Keep going"],
- [ "1) Look for the shortest alternative", "2) Look for the fastest alternative", "3) No, keep going"]
- ]
- #function that displays a report of statistics from the answers given
- def review_report():
- print("\n*** Report of given answers ***")
- #loop that calculates the statistics of each question
- for i in range(len(questions)):
- print(questions[i])
- answered = given_answers[i]
- sum_answers = sum(answered)
- if sum_answers == 0:
- print("\n- -> No question asked!")
- continue
- #calculate the percentage for each answer
- for j in range(len(answers[i])):
- percent_value = 100 * (given_answers[i][j] / sum_answers)
- print(f"\t-> {round(percent_value)}% {answers[i][j]}")
- #function that asks the user questions
- def give_answer():
- print("\n*** Give answer ***")
- #prepare questions to a new list in a random order
- random_questions = []
- for i in range(len(questions)):
- random_questions.append(i)
- random.shuffle(random_questions)
- #loop displaying questions and answers
- ## 3 - HERE WE CREATE THE CODE THAT ASKS THE QUESTIONS ##.
- ## 1 - HERE WE INITIATE THE LIST & VARIABLE ##.
- #menu handling
- ## menu operation
- while choice != 0:
- ## displaying menu options
- print("\n*** What to do? ***")
- print("1. Review the report")
- print("2. Give answer")
- print("0. Exit")
- #getting values from the user
- ## 2 - HERE WE CREATE CODE THAT RESPONDS TO THE USER'S CHOICE ##.
- break
Add Comment
Please, Sign In to add comment