SHOW:
|
|
- or go back to the newest paste.
1 | import random | |
2 | ||
3 | # List of questions asked by the computer, you can add your own, but you need to change the answers in that case. | |
4 | questions = [ | |
5 | "Rainfall detected. Should you change your speed? [87 km/h]", | |
6 | "Identified 'Sharp Turns' sign. Should you change your speed? [103 km/h]", | |
7 | "The vehicle in front suddenly brakes. Collision is imminent. What should you do?", | |
8 | "Identified 'bicycle' ahead [8 km/h]. What should you do?", | |
9 | "Fuel level is less than 1/3. Should you change your route?", | |
10 | "Collision detected on the route, 10 km ahead. Should you change your route?", | |
11 | ] | |
12 | ||
13 | # List of answers in the order of questions asked, you can add your own. | |
14 | answers = [ | |
15 | ["1) Increase speed", "2) Reduce speed", "3) Maintain current speed"], | |
16 | ["1) Increase speed", "2) Reduce speed", "3) Maintain current speed"], | |
17 | ["1) Change lanes to the left", "2) Move to the shoulder", "3) Brake without changing lanes"], | |
18 | ["1) Change lanes to the left", "2) Overtake and return to the right lane", "3) No, continue straight"], | |
19 | ["1) Look for a gas station within 30 km", "2) Look for a gas station within 50 km", "3) Keep driving"], | |
20 | ["1) Look for the shortest alternative", "2) Look for the fastest alternative", "3) No, keep driving"], | |
21 | ] | |
22 | ||
23 | # Function to display a statistics report of given answers | |
24 | def review_report(): | |
25 | print("\n*** Report of Given Answers ***") | |
26 | ||
27 | # Loop to calculate statistics for each question | |
28 | for i in range(len(questions)): | |
29 | print(questions[i]) | |
30 | answered = given_answers[i] | |
31 | total_answers = sum(answered) | |
32 | ||
33 | if total_answers == 0: | |
34 | print("\t -> Question not asked!") | |
35 | continue | |
36 | ||
37 | # Calculate the percentage for each answer | |
38 | for j in range(len(answers[i])): | |
39 | percentage_value = 100 * (given_answers[i][j] / total_answers) | |
40 | print(f"\t-> {round(percentage_value)}% {answers[i][j]}") | |
41 | ||
42 | # Function to ask questions to the user | |
43 | def provide_answers(): | |
44 | print("\n*** Provide Answers ***") | |
45 | ||
46 | # Copy questions to a new list in random order | |
47 | random_questions = [] | |
48 | for i in range(len(questions)): | |
49 | random_questions.append(i) | |
50 | random.shuffle(random_questions) | |
51 | ||
52 | # Loop to display questions and answers | |
53 | ## 3 - HERE, WE CREATE CODE TO ASK QUESTIONS ## | |
54 | ||
55 | ||
56 | # Initialize the list and variable here | |
57 | given_answers = [] | |
58 | choise = -1 | |
59 | ||
60 | # Menu handling | |
61 | while choise != 0: | |
62 | # Display menu options | |
63 | print("\n*** What to do? ***") | |
64 | print("1. Review Report") | |
65 | print("2. Provide Answers") | |
66 | print("0. Exit") | |
67 | ||
68 | # Get user input here | |
69 | ## 2 - HERE, CREATE CODE TO RESPOND TO USER'S CHOICE ## | |
70 | break | |
71 |