Question

In: Computer Science

The driver’s license office DMV has asked you to write a program that grades the written...

The driver’s license office DMV has asked you to write a program that grades the written portion of the driver’s license questions. The questions has 20 multiple-choice questions. Here are the correct answers:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

B

D

A

A

A

C

B

C

D

A

D

C

C

D

D

B

A

B

C

D

Your program should store these correct answers in a list. The program should first ask the user for the filename that stores the answers. Then, read the student’s answers for each of the 20 questions from a text file specified by the user and store the answers in another list. (I have provided a sample file called answers1.txt) After the student’s answers have been read from the file, the program should display a message indicating whether the student passed ('You passed") or failed ("You failed") the exam. (A student must correctly answer 15 of the 20 questions to pass the exam.) It should then display the total number of correctly answered questions, the total number of incorrectly answered questions, and a list showing the question numbers of the incorrectly answered questions (and the correct answers). For example, the given asnwers1.txt file will generate the following output:

enter file name: answers1.txt
You failed
Total correct: 13 Questions # = 3, 4, 6, 7, 8, 10, 12, 13, 15, 16, 17, 19, 20
Total incorrect: 7 Questions # = 1, 2, 5, 9, 11, 14, 18
Correct answers for incorrect questions are:
1 : B
2 : D
5 : A
9 : D
11 : D
14 : D
18 : B

Solutions

Expert Solution

Here is the completed code for this problem. Assuming the language is Python. Please don’t forget to mention the language while you post a question in future. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. If not, PLEASE let me know before you rate, I’ll help you fix whatever issues. Thanks

Note: Please maintain proper code spacing (indentation), just copy the code part and paste it in your compiler/IDE directly, no modifications required.

#code

# hardcoding a list of correct answers
correct_answers = ['B', 'D', 'A', 'A', 'A', 'C', 'B', 'C', 'D', 'A', 'D', 'C', 'C', 'D', 'D', 'B', 'A', 'B', 'C', 'D']

# asking, reading file name
filename = input("enter file name: ")
# opening file in read mode, assuming file exist
file = open(filename, 'r')

# assuming the answers are listed in a single line on the file
# reading a line, splitting by white space to get a list of answers
answers = file.readline().strip().split()
# closing file
file.close()

# creating two lists to store question numbers of right and wrong answers
correct = []
wrong = []

# looping through answers list, assuming len(answers) is 20
for i in range(len(answers)):
    # comparing answers at index i
    if answers[i] == correct_answers[i]:
        # correct, adding i+1 (question numbers start from 1) to correct answers list
        correct.append(i + 1)
    else:
        # wrong, appending i+1 to wrong answers list
        wrong.append(i + 1)

# if user managed to answer at least 15 right answers, he/she passed
if len(correct) >= 15:
    print("You passed")
else:
    print("You failed")

# printing count of right/wrong answers and the corresponding question numbers
# ', '.join([str(i) for i in correct]) will print each element in correct comma separated
print('Total correct: {} Questions # = {}'.format(len(correct), ', '.join([str(i) for i in correct])))
print('Total incorrect: {} Questions # = {}'.format(len(wrong), ', '.join([str(i) for i in wrong])))

# if user had submitted any wrong answer(s), displaying each question number and the right answer
if len(wrong) > 0:
    print('Correct answers for incorrect questions are:')
    for i in wrong:
        print('{} : {}'.format(i, correct_answers[i - 1]))

#output

enter file name: answers.txt
You passed
Total correct: 16 Questions # = 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 17, 19, 20
Total incorrect: 4 Questions # = 1, 9, 16, 18
Correct answers for incorrect questions are:
1 : B
9 : D
16 : B
18 : B

#answers.txt file that I used

C D A A A C B C A A D C C D D D A A C D

Related Solutions

Driver’s License test. Write a program that grades the written portion of the driver’s license test....
Driver’s License test. Write a program that grades the written portion of the driver’s license test. The test has 20 multiple choice questions. Here are the correct answers: ( use array to store ) 1.B 2.D 3. A 4. A 5. C 6. A 7. B 8. A 9. C 10. D 11.B 12. C 13. D 14. A 15. D 16. C 17. C 18. B 19. D 20. A A student must correctly answer ( use array to...
The local driver's license office has asked you to design a program that grades the written...
The local driver's license office has asked you to design a program that grades the written portion of the driver's license exam. The exam has 20 multiple choice questions. Here are the correct answers: B D A A C A B A C D B C D A D C C B D A Your program should store these correct answers in an list. (Store each question's correct answer in an element of a String list). The program should ask...
The local driver's license office has asked you to design a program that grades the written...
The local driver's license office has asked you to design a program that grades the written portion of the driver's license test. The test has 20 multiple choice questions. Here are the correct answers: B D A A C A B A C D B C D A D C C B D A Your program should store these correct answers in an list. (Store each question's correct answer in an element of a String list). The program should ask...
A sample of 31 people took a written driver’s license exam. Two variables were measured on...
A sample of 31 people took a written driver’s license exam. Two variables were measured on them: The result of the exam (0 = fail, 1 = pass), and how much time (in hours) the person studied for the exam. Using the data, fit an appropriate regression model to determine whether time spent studying is a useful predictor of the chance of passing the exam. Formally assess the overall fit of the model. Formally assess whether time spent studying is...
You need to get a driver’s license. There is a clerk A, a clerk B, a...
You need to get a driver’s license. There is a clerk A, a clerk B, a clerk C, a clerk D, and a clerk E. Assuming that the work each clerk does is value adding, answer these two questions. Calculate the amount of time in the process that is value adding and the amount that is wait time. What is the bottleneck? Department of Motor Vehicle process: A. Check in, clerk A puts your name into the computer. Clerk A...
Write the program in C++ The Rebel food truck has asked you to write a program...
Write the program in C++ The Rebel food truck has asked you to write a program for them to do both inventory and sales for their food wagon. Ben and Dave run the food truck and they already have full time day jobs so they could really use your help. The food truck sells: hamburger, hotdogs, chilli, fries and soda. The truck has spots for 200 hamburger patties, 200 hot dogs, 75 hamburger buns, 75 hot dog buns, 500 ounces...
Who knows how to do pseudocode on this topic? The local driver's license office has asked...
Who knows how to do pseudocode on this topic? The local driver's license office has asked you to design a program that grades the written portion of the driver's license exam. The exam has 20 multiple choice questions. Here are the correct answers: 1. B 2. D 3. A 4. A 5. C 6. A 7. B 8. A 9. C 10. D 11. B 12. C 13. D 14. A 15. D 16. C 17. C 18. B 19....
Python Language: The Marietta Country Club has asked you to write a program to gather, then...
Python Language: The Marietta Country Club has asked you to write a program to gather, then display the results of the golf tournament played at the end of March. The Club president Mr. Martin has asked you to write two programs. The first program will input each player's first name, last name, handicap and golf score and then save these records in a file named golf.txt (each record will have a field for the first name, last name, handicap and...
Coding Problem 1: In this program, you are asked to write a program in assembly (MIPS)...
Coding Problem 1: In this program, you are asked to write a program in assembly (MIPS) which works as a simple calculator. The program will get two integer numbers, and based on the requested operation, the result should be shown to the user. a. The program should print a meaningful phrase for each input, and the result. i. “Enter the first number” ii. “Enter the second number” iii. “Enter the operation type” iv. “The result is” b. The user should...
For Python: In this assignment you are asked to write a Python program to determine the...
For Python: In this assignment you are asked to write a Python program to determine the Academic Standing of a studentbased on their CGPA. The program should do the following: Prompt the user to enter his name. Prompt the user to enter his major. Prompt the user to enter grades for 3 subjects (A, B, C, D, F). Calculate the CGPA of the student. To calculate CGPA use the formula: CGPA = (quality points * credit hours) / credit hours...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT