View difference between Paste ID: 0PrNFi42 and K18Y7P7Y
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 have to change the answers then
4
questions = [
5
"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]",
6
"The vehicle in front of me suddenly brakes. There is no avoiding a collision. What to do?",
7
"A vehicle in front of us has been identified as 'bicycle' [8 km/h]. What to do?",
8
"The fuel level is less than 1/3, should we change the route?",
9
"A collision was detected on the route at a distance of 10km. Modify the route?",
10
]
11
12
#list of answers in order of questions asked, you can add your
13
answers = [
14
[ "1) Increase speed", "2) Decrease speed", "3) Don't change speed"],
15
[ "1) Increase speed", "2) Decrease speed", "3) Don't change speed"],
16
[ "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"],
17
[ "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"],
18
[ "1) Look for the shortest alternative", "2) Look for the fastest alternative", "3) No, keep going"]
19
]
20
21
#function that displays a report of statistics from the answers given
22
def review_report():
23
    print("\n*** Report of given answers ***")
24
   
25
    #loop that calculates the statistics of each question
26
    for i in range(len(questions)):         
27
        print(questions[i])
28
        answered = given_answers[i]
29
        sum_answers = sum(answered)
30
 
31
        if sum_answers == 0:
32
            print("\n- -> No question asked!")
33
            continue
34
       
35
        #calculate the percentage for each answer
36
        for j in range(len(answers[i])):
37
            percent_value = 100 * (given_answers[i][j] / sum_answers)
38
            print(f"\t-> {round(percent_value)}%  {answers[i][j]}")
39
40
#function that asks the user questions
41
def give_answer():
42
    print("\n*** Give answer ***")
43
   
44
    #prepare questions to a new list in a random order
45
    random_questions = []             
46
    for i in range(len(questions)):
47
        random_questions.append(i)
48
    random.shuffle(random_questions)
49
   
50
    #loop displaying questions and answers
51
    ## 3 - HERE WE CREATE THE CODE THAT ASKS THE QUESTIONS ##.
52
   
53
54
## 1 - HERE WE INITIATE THE LIST & VARIABLE ##.
55
56
#menu handling
57
  
58
## menu operation
59
while choice != 0:
60
    ## displaying menu options
61
    print("\n*** What to do? ***")             
62
    print("1. Review the report")
63
    print("2. Give answer")
64
    print("0. Exit")
65
66
67
    #getting values from the user
68
    ## 2 - HERE WE CREATE CODE THAT RESPONDS TO THE USER'S CHOICE ##.
69
    break