To whom this may concern: Below is the problem I am stuck on: I will first submi
ID: 3763770 • Letter: T
Question
To whom this may concern:
Below is the problem I am stuck on:
I will first submit to you my work so far. Could you please let me know where I am making the mistakes in the program. I will also post the correct output that I need.
def main():
# Setup variables
corr_ans_list = ["A", "C", "A", "A", "D", "B",
"C", "A", "C", "B", "A", "D",
"C", "A", "D", "C", "B", "B",
"D", "A"]
user_ans_list = []
corr_count = 0
num_questions = 20
# Setup file variable and open the user_answers.txt file
infile = open('user_answers.txt', 'r')
# Place statements to load usr_ans_list from the file. Remember to
# rstrip the character
user_ans = infile.readlines()
index = 0
while index < len(user_ans):
user_ans[index] = user_ans[index].rstrip(' ')
index += 1
print("Q corr Your Status")
print("# Answer Answer --------------------------")
# Code for loop to process each element from corr_ans_lit and
# usr_ans_list and update corr_count counter variable accordingly
for i in range(20):
print(corr_ans_list[i],user_ans[i])
if corr_ans_list[i] == user_ans[i]:
corr_count += 1
else:
corr_ans_list[i] != user_ans[i]
print('x')
percent_corr = (corr_count/num_questions) * 100
percent_corr_fmt = format(percent_corr, ".1f")
print(" Grade : ", corr_count , "/", num_questions, " = ",
percent_corr_fmt, sep="")
# Determine if student passed and display result
if percent_corr >= 75:
print("Congratulations!! You passed the exam")
else:
print("Sorry, you did not pass the exam")
# Close file
infile.close()
main()
The correct output need:
Q corr Your Status
# Ans. Ans.
---------------------------------------
1 A A
2 C C
3 A A
4 A B X
5 D D
6 B B
7 C C
8 A A
9 C C
10 B B
11 A B X
12 D B
13 C C
14 A A
15 D D
16 C B X
17 B B
18 B B
19 D B X
20 A A
Grade : 16/20 = 80.0
Congratulations!! You passed the exam
Explanation / Answer
Setup variables
corr_ans_list = ["A", "C", "A", "A", "D", "B",
"C", "A", "C", "B", "A", "D",
"C", "A", "D", "C", "B", "B",
"D", "A"]
user_ans_list = []
corr_count = 0
num_questions = 20
# Setup file variable and open the user_answers.txt file
infile = open('user_answers.txt', 'r')
# Place statements to load usr_ans_list from the file. Remember to
# rstrip the character
user_ans = infile.readlines()
index = 0
while index < len(user_ans):
user_ans[index] = user_ans[index].rstrip(' ')
index += 1
print("Q corr Your Status")
print("# Answer Answer --------------------------")
# Code for loop to process each element from corr_ans_lit and
# usr_ans_list and update corr_count counter variable accordingly
for i in range(20):
print(corr_ans_list[i],user_ans[i])
if corr_ans_list[i] == user_ans[i]:
corr_count += 1
else:
corr_ans_list[i] != user_ans[i]
print('x')
percent_corr = (corr_count/num_questions) * 100
percent_corr_fmt = format(percent_corr, ".1f")
print(" Grade : ", corr_count , "/", num_questions, " = ",
percent_corr_fmt, sep="")
# Determine if student passed and display result
if percent_corr >= 75:
print("Congratulations!! You passed the exam")
else:
print("Sorry, you did not pass the exam")
# Close file
infile.close()
main()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.