Repository navigation
Expand file tree
/
Copy pathlogic_plane.py
More file actions
106 lines (88 loc) · 3.36 KB
/
Copy pathlogic_plane.py
File metadata and controls
106 lines (88 loc) · 3.36 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import json
import random
from collections import defaultdict
# Load the JSON file
with open('plane.json', 'r', encoding='utf-8') as f:
data = json.load(f)
# Extract questions from Easy, Medium, Hard
easy_questions = []
medium_questions = []
hard_questions = []
# Navigate the structure
physics = data.get("Physics", {})
motion_plane = physics.get("Motion in Plane", {})
# Easy
if "Easy" in motion_plane:
for subtopic_name, questions in motion_plane["Easy"].items():
for q in questions:
q['subtopic'] = subtopic_name
q['difficulty'] = 'easy'
easy_questions.append(q)
# Medium
if "Medium" in motion_plane:
for subtopic in motion_plane["Medium"]:
sub_name = subtopic.get("name", "Unknown")
for q in subtopic.get("questions", []):
q['subtopic'] = sub_name
q['difficulty'] = 'medium'
medium_questions.append(q)
# Hard
if "Hard" in motion_plane:
for subtopic in motion_plane["Hard"]:
sub_name = subtopic.get("name", "Unknown")
for q in subtopic.get("questions", []):
q['subtopic'] = sub_name
q['difficulty'] = 'hard'
hard_questions.append(q)
# Select questions
selected = []
selected.extend(random.sample(easy_questions, min(10, len(easy_questions))))
selected.extend(random.sample(medium_questions, min(12, len(medium_questions))))
selected.extend(random.sample(hard_questions, min(8, len(hard_questions))))
random.shuffle(selected)
def run_quiz(questions):
score = 0
total = len(questions)
user_answers = {}
print("\n=== MOTION IN PLANE - MIXED DIFFICULTY QUIZ ===\n")
for i, q in enumerate(questions, 1):
print(f"Q{i}. {q['question']}")
for opt in q.get('options', []):
print(opt)
ans = input("Your answer (A/B/C/D): ").strip().upper()
user_answers[q['qid']] = ans
correct = q.get('answer', '')
if ans == correct:
score += 1
print("✅ Correct!\n")
else:
print(f"❌ Wrong! Correct answer: {correct}\n")
print("-" * 60)
percentage = (score / total) * 100 if total > 0 else 0
print(f"\n🎯 Your Final Score: {score}/{total} ({percentage:.2f}%)")
# Weak topic analysis
subtopic_perf = defaultdict(lambda: {'correct': 0, 'total': 0})
for q in questions:
sub = q.get('subtopic', 'Unknown')
subtopic_perf[sub]['total'] += 1
if user_answers.get(q['qid']) == q.get('answer'):
subtopic_perf[sub]['correct'] += 1
print("\n📊 Performance by Subtopic:")
weak_topics = []
for sub, perf in subtopic_perf.items():
perc = (perf['correct'] / perf['total']) * 100 if perf['total'] > 0 else 0
print(f" {sub}: {perf['correct']}/{perf['total']} ({perc:.1f}%)")
if perc < 60:
weak_topics.append(sub)
if weak_topics:
print(f"\n⚠️ Weak Topics (below 60%): {', '.join(weak_topics)}")
print("Recommendation: Revise these topics.")
else:
print("\n🎉 Excellent! No weak topics identified.")
return percentage
# Run the quiz
if __name__ == "__main__":
if not selected:
print("No questions loaded. Check the JSON file.")
else:
run_quiz(selected)