-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformat_answers.py
More file actions
50 lines (40 loc) · 1.69 KB
/
format_answers.py
File metadata and controls
50 lines (40 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import json
# Load the JSON files
try:
with open('questions.json', 'r') as f:
questions_data = json.load(f)
except:
print("Error: Cannot find questions.json file")
exit(1)
try:
with open('answers.json', 'r') as f:
answers_data = json.load(f)
except:
answers_data = {}
print(f"# Quiz Results")
print(f"The user was asked the folling questions. A response of 'NO RESPONSE' indicates that the user did not respond to the question.\n")
# Calculate total questions and number correct
total_questions = len(questions_data['elements'])
correct_answers = sum(1 for answer in answers_data.values() if hasattr(answer, 'get') and answer.get('isCorrect', False))
print(f"## SCORE:\n{correct_answers} out of {total_questions} questions correct ({(correct_answers/total_questions)*100:.1f}%)\n")
print(f"## QUESTIONS:\n")
# Create a dictionary mapping question names to their titles and correct answers
questions = {
q['name']: {
'title': q['title'],
'correctAnswer': q.get('correctAnswer', 'Unknown')
} for q in questions_data['elements']
}
# Format and display each question with its answer
for q_name, q_info in questions.items():
print(f"### {q_info['title']}")
# Get the corresponding answer if it exists
answer_data = answers_data.get(q_name, {})
user_answer = answer_data.get('value', 'NO RESPONSE')
expected_answer = q_info['correctAnswer'] # Get correct answer from questions data
is_correct = answer_data.get('isCorrect', False)
# Print formatted results
print(f"- user response: {user_answer}")
print(f"- expected response: {expected_answer}")
print(f"- is correct? {'yes' if is_correct else 'no'}")
print("")