~/msk-mcq/generate_mcq_pdf.py
from reportlab.lib.pagesizes import A4
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.units import cm
from reportlab.lib import colors
from reportlab.platypus import (
SimpleDocTemplate, Paragraph, Spacer, Table, TableStyle,
HRFlowable, KeepTogether
)
from reportlab.lib.enums import TA_LEFT, TA_CENTER, TA_JUSTIFY
OUTPUT = "/home/daytona/workspace/msk-mcq/MSK_Anatomy_MCQ_40Q.pdf"
# ββ 40 Questions βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
questions = [
# BONES
{
"n": 1, "topic": "Bones β Classification",
"q": "Which of the following is classified as a sesamoid bone?",
"opts": ["A. Scaphoid", "B. Patella", "C. Pisiform", "D. Hamate"],
"ans": "B",
"exp": "The patella is the largest sesamoid bone in the body, embedded in the quadriceps/patellar tendon. The pisiform is a sesamoid-like carpal but technically classified as a short bone."
},
{
"n": 2, "topic": "Bones β Structure",
"q": "The nutrient foramen of long bones is directed:",
"opts": ["A. Toward the growing end (epiphysis)", "B. Away from the growing end", "C. Perpendicular to the bone axis", "D. Toward the nearest joint"],
"ans": "B",
"exp": "The nutrient canal/foramen is directed away from the growing end β classically 'toward the elbow, away from the knee.' This is a well-known anatomical rule."
},
{
"n": 3, "topic": "Bones β Cells",
"q": "Which bone cell is derived from monocyte/macrophage lineage and is responsible for bone resorption?",
"opts": ["A. Osteoblast", "B. Osteocyte", "C. Osteoclast", "D. Chondroblast"],
"ans": "C",
"exp": "Osteoclasts are large, multinucleated cells derived from monocyte/macrophage precursors (hematopoietic lineage). They resorb bone via acidification and proteolytic enzymes in the ruffled border."
},
{
"n": 4, "topic": "Bones β Marrow",
"q": "Red (hematopoietic) bone marrow is retained in adults in all of the following EXCEPT:",
"opts": ["A. Sternum", "B. Vertebral bodies", "C. Diaphysis of femur", "D. Iliac crest"],
"ans": "C",
"exp": "In adults, the diaphysis of long bones contains yellow (fatty) marrow. Red marrow is retained in flat bones (sternum, iliac crest, skull), ribs, vertebrae, and the proximal epiphyses of long bones (humerus, femur)."
},
# JOINTS
{
"n": 5, "topic": "Joints β Classification",
"q": "The pubic symphysis is an example of which type of joint?",
"opts": ["A. Synovial joint", "B. Primary cartilaginous (synchondrosis)", "C. Secondary cartilaginous (symphysis)", "D. Fibrous (syndesmosis)"],
"ans": "C",
"exp": "Secondary cartilaginous joints (symphyses) are united by fibrocartilage β e.g., pubic symphysis, intervertebral discs, manubriosternal joint. Primary cartilaginous joints use hyaline cartilage (e.g., epiphyseal plates, costochondral joints)."
},
{
"n": 6, "topic": "Joints β Synovial",
"q": "Which component of a synovial joint receives nutrition primarily by diffusion from synovial fluid, making it avascular and therefore poorly healing?",
"opts": ["A. Synovial membrane", "B. Articular (hyaline) cartilage", "C. Joint capsule fibrous layer", "D. Subchondral bone"],
"ans": "B",
"exp": "Articular hyaline cartilage is avascular, aneural, and alymphatic. It has no perichondrium and relies entirely on diffusion from synovial fluid for nutrition β hence its poor intrinsic healing capacity."
},
{
"n": 7, "topic": "Joints β Synovial Types",
"q": "The 1st carpometacarpal joint (thumb CMC) is classified as which type of synovial joint?",
"opts": ["A. Ball-and-socket", "B. Condyloid (ellipsoidal)", "C. Saddle (sellar)", "D. Hinge (ginglymus)"],
"ans": "C",
"exp": "The 1st CMC joint is a saddle (sellar) joint β each articular surface is concave in one plane and convex in the other. It allows flexion/extension, abduction/adduction, and opposition (combined movement)."
},
{
"n": 8, "topic": "Joints β Pivot",
"q": "Which of the following joints is correctly classified as a pivot (trochoid) joint?",
"opts": ["A. Radiocarpal joint", "B. Atlantoaxial (C1βC2) joint", "C. Glenohumeral joint", "D. Talocrural (ankle) joint"],
"ans": "B",
"exp": "The atlantoaxial joint is a pivot joint β C1 rotates around the dens of C2, allowing ~50% of total cervical rotation. The proximal radioulnar joint is another classic pivot joint."
},
# SHOULDER
{
"n": 9, "topic": "Shoulder β Rotator Cuff",
"q": "Which rotator cuff muscle initiates abduction of the arm (0β15Β°) and is most commonly torn?",
"opts": ["A. Infraspinatus", "B. Subscapularis", "C. Supraspinatus", "D. Teres minor"],
"ans": "C",
"exp": "Supraspinatus initiates abduction from 0β15Β°. The deltoid takes over from 15β90Β°. Supraspinatus is the most commonly torn rotator cuff muscle β tears occur at the 'critical zone' near its insertion on the greater tubercle."
},
{
"n": 10, "topic": "Shoulder β Rotator Cuff",
"q": "Which rotator cuff muscle originates from the subscapular fossa (anterior/costal surface of scapula) and is the only internal rotator in the group?",
"opts": ["A. Supraspinatus", "B. Infraspinatus", "C. Teres minor", "D. Subscapularis"],
"ans": "D",
"exp": "Subscapularis is the only rotator cuff muscle on the anterior (costal) surface of the scapula. It inserts on the lesser tubercle and is the primary internal rotator. The other three (SITS minus S) are posterior and are external rotators/abductors."
},
{
"n": 11, "topic": "Shoulder β Nerves",
"q": "Fracture of the surgical neck of the humerus most commonly injures which nerve, causing loss of deltoid function and a 'flat shoulder' appearance?",
"opts": ["A. Radial nerve", "B. Musculocutaneous nerve", "C. Axillary nerve", "D. Suprascapular nerve"],
"ans": "C",
"exp": "The axillary nerve (C5βC6) winds around the surgical neck of the humerus. Injury causes paralysis of deltoid (abduction loss) and teres minor, plus sensory loss over the 'regimental badge' area (lateral arm)."
},
{
"n": 12, "topic": "Shoulder β Scapular Movement",
"q": "Which muscle is primarily responsible for protracting the scapula AND rotating it upward, and its paralysis leads to a winged scapula?",
"opts": ["A. Trapezius", "B. Serratus anterior", "C. Rhomboid major", "D. Levator scapulae"],
"ans": "B",
"exp": "Serratus anterior (long thoracic nerve, C5βC7) holds the scapula against the thorax, protracts it, and rotates it upward. Paralysis causes a 'winged scapula' β medial border lifts away from thorax, especially when pushing against a wall."
},
# ELBOW & FOREARM
{
"n": 13, "topic": "Elbow β Muscles",
"q": "Which muscle is considered the 'workhorse' of elbow flexion because it acts regardless of forearm position (pronated or supinated)?",
"opts": ["A. Biceps brachii", "B. Brachialis", "C. Brachioradialis", "D. Pronator teres"],
"ans": "B",
"exp": "Brachialis is the only pure elbow flexor β it inserts on the coronoid process and ulnar tuberosity and acts in all forearm positions. Biceps brachii is more powerful in supination. Brachioradialis is most efficient in the mid-prone position."
},
{
"n": 14, "topic": "Elbow β Nerve Injury",
"q": "A midshaft fracture of the humerus ('Holstein-Lewis fracture') injures the radial nerve in the radial groove. Which finding would you expect?",
"opts": ["A. Loss of elbow flexion", "B. Wrist drop and loss of finger extension", "C. Thenar wasting and loss of thumb opposition", "D. Claw hand deformity of digits 4β5"],
"ans": "B",
"exp": "Radial nerve injury causes wrist drop (inability to extend wrist) and loss of finger/thumb extension (but intrinsics mostly spared via ulnar/median). Sensation is lost over dorsal first web space."
},
# WRIST & HAND
{
"n": 15, "topic": "Wrist β Carpal Bones",
"q": "Which carpal bone is most commonly fractured and at risk of avascular necrosis due to its retrograde blood supply?",
"opts": ["A. Lunate", "B. Triquetrum", "C. Scaphoid", "D. Capitate"],
"ans": "C",
"exp": "The scaphoid is the most commonly fractured carpal bone (fall on outstretched hand). Its blood supply enters distally β fractures at the waist can disrupt supply to the proximal pole, causing avascular necrosis."
},
{
"n": 16, "topic": "Wrist β Carpal Tunnel",
"q": "Which structure passes through the carpal tunnel MOST medially and is at risk in carpal tunnel syndrome?",
"opts": ["A. Ulnar nerve", "B. Median nerve", "C. Radial artery", "D. Flexor carpi radialis tendon"],
"ans": "B",
"exp": "The carpal tunnel contains 9 flexor tendons (4 FDS, 4 FDP, 1 FPL) and the median nerve. The ulnar nerve and artery travel through Guyon's canal (ulnar tunnel), which is outside the carpal tunnel."
},
{
"n": 17, "topic": "Hand β Nerve Injury",
"q": "Injury to the ulnar nerve at the wrist produces a 'claw hand' involving primarily:",
"opts": ["A. Digits 1β3", "B. Digits 2β3", "C. Digits 4β5", "D. All 5 digits equally"],
"ans": "C",
"exp": "Ulnar nerve injury at the wrist causes clawing of the 4th and 5th digits (ring and little fingers) due to loss of the medial two lumbricals and hypothenar muscles. The 'intrinsic minus' hand cannot flex at MCPs and extend at IPs."
},
{
"n": 18, "topic": "Hand β Median Nerve",
"q": "Injury to the median nerve at the elbow (e.g., supracondylar fracture) results in which classic deformity when asked to make a fist?",
"opts": ["A. Wrist drop", "B. Claw hand of digits 4β5", "C. 'Benediction hand' β digits 2β3 extended, 4β5 flexed", "D. Loss of little finger abduction only"],
"ans": "C",
"exp": "High median nerve injury at the elbow: FDS, FDP (digits 2β3), and FPL are lost. When making a fist, digits 2β3 remain extended ('pointing') while 4β5 flex (supplied by ulnar). This is the 'papal blessing/benediction' hand."
},
# HIP
{
"n": 19, "topic": "Hip β Ligaments",
"q": "Which ligament of the hip joint is considered the strongest ligament in the human body and prevents hyperextension?",
"opts": ["A. Pubofemoral ligament", "B. Ischiofemoral ligament", "C. Ligamentum teres", "D. Iliofemoral ligament (Y-ligament of Bigelow)"],
"ans": "D",
"exp": "The iliofemoral ligament (inverted Y-shape) is the strongest ligament in the body. It tightens in extension and external rotation, preventing hyperextension of the hip during standing."
},
{
"n": 20, "topic": "Hip β Blood Supply",
"q": "Which artery is the primary blood supply to the femoral head in adults, making femoral neck fractures liable to avascular necrosis?",
"opts": ["A. Inferior gluteal artery", "B. Medial circumflex femoral artery", "C. Lateral circumflex femoral artery", "D. Obturator artery via ligamentum teres"],
"ans": "B",
"exp": "The medial circumflex femoral artery (branch of the profunda femoris) provides ~80% of blood to the femoral head via retinacular vessels. Its disruption in femoral neck fractures is the primary cause of AVN."
},
{
"n": 21, "topic": "Hip β Muscles",
"q": "A patient stands on the right leg and the left side of the pelvis drops. Which muscle on which side is weak?",
"opts": ["A. Right hip adductors", "B. Left hip abductors (gluteus medius)", "C. Right hip abductors (gluteus medius)", "D. Left hip flexors (iliopsoas)"],
"ans": "C",
"exp": "Positive Trendelenburg sign: the unsupported (contralateral) side drops. The problem is on the stance (ipsilateral) side β right gluteus medius is weak. The superior gluteal nerve (L4βS1) innervates gluteus medius/minimus."
},
{
"n": 22, "topic": "Hip β External Rotators",
"q": "How many 'short external rotators' of the hip are there, and which is the most superior?",
"opts": ["A. 4; obturator internus", "B. 5; piriformis", "C. 6; piriformis", "D. 6; quadratus femoris"],
"ans": "C",
"exp": "There are 6 short external rotators: piriformis (most superior), superior gemellus, obturator internus, inferior gemellus, obturator externus, and quadratus femoris (most inferior). All insert on/near the greater trochanter."
},
# KNEE
{
"n": 23, "topic": "Knee β Ligaments",
"q": "Which ligament of the knee prevents anterior translation of the tibia on the femur and is most commonly injured in sports?",
"opts": ["A. Posterior cruciate ligament (PCL)", "B. Medial collateral ligament (MCL)", "C. Anterior cruciate ligament (ACL)", "D. Lateral collateral ligament (LCL)"],
"ans": "C",
"exp": "The ACL prevents anterior tibial translation and is taut in extension. It is the most commonly injured knee ligament in sports (pivoting, cutting movements). Lachman's test (at 20β30Β° flexion) is the most sensitive test."
},
{
"n": 24, "topic": "Knee β Menisci",
"q": "Why is the medial meniscus more commonly torn than the lateral meniscus?",
"opts": ["A. It is more circular and mobile", "B. It is firmly attached to the medial collateral ligament, reducing its mobility", "C. It is thicker and less vascular", "D. It is in contact with the patella"],
"ans": "B",
"exp": "The medial meniscus is C-shaped and firmly attached to the MCL. This restricts its mobility, making it more susceptible to shearing forces. The lateral meniscus is more circular and freely mobile (no LCL attachment), so it moves with the tibia and avoids injury."
},
{
"n": 25, "topic": "Knee β Unhappy Triad",
"q": "O'Donoghue's 'unhappy triad' involves injury to which three structures?",
"opts": [
"A. ACL + LCL + lateral meniscus",
"B. ACL + MCL + medial meniscus",
"C. PCL + MCL + medial meniscus",
"D. ACL + PCL + lateral meniscus"
],
"ans": "B",
"exp": "The unhappy triad (O'Donoghue) = ACL + MCL + medial meniscus. A valgus force on the flexed knee (e.g., clipping tackle) injures all three, because the MCL is attached to the medial meniscus and the ACL fails with tibial anterior translation."
},
{
"n": 26, "topic": "Knee β Nerve in Popliteal Fossa",
"q": "Fracture of the fibular neck most commonly injures which nerve, producing foot drop and loss of eversion?",
"opts": ["A. Tibial nerve", "B. Common fibular (peroneal) nerve", "C. Saphenous nerve", "D. Sural nerve"],
"ans": "B",
"exp": "The common fibular nerve winds around the neck of the fibula, making it vulnerable to fractures here. Its deep branch supplies the anterior compartment (dorsiflexion); its superficial branch supplies the lateral compartment (eversion). Foot drop + loss of eversion = complete injury."
},
# ANKLE & FOOT
{
"n": 27, "topic": "Ankle β Joints",
"q": "Inversion and eversion of the foot primarily occur at which joint?",
"opts": ["A. Talocrural (tibiotalar) joint", "B. Subtalar (talocalcaneal) joint", "C. Transverse tarsal (Chopart) joint", "D. Tarsometatarsal (Lisfranc) joint"],
"ans": "B",
"exp": "The subtalar joint (between talus and calcaneus) is the primary joint for inversion and eversion. The talocrural (ankle) joint is a hinge for dorsiflexion/plantarflexion only."
},
{
"n": 28, "topic": "Ankle β Ligament Injury",
"q": "The most commonly sprained ligament in the ankle during a lateral inversion injury is the:",
"opts": ["A. Deltoid ligament", "B. Calcaneofibular ligament", "C. Posterior talofibular ligament", "D. Anterior talofibular ligament (ATFL)"],
"ans": "D",
"exp": "ATFL is the weakest and most anterior of the lateral ankle ligaments. In a typical inversion sprain, it tears first, followed by the calcaneofibular ligament. The deltoid ligament is medial and much stronger."
},
{
"n": 29, "topic": "Leg β Compartments",
"q": "A patient develops pain, pallor, and loss of dorsiflexion after a tibial fracture. Pressure is elevated in which compartment?",
"opts": ["A. Lateral (fibular) compartment", "B. Superficial posterior compartment", "C. Anterior compartment", "D. Deep posterior compartment"],
"ans": "C",
"exp": "The anterior compartment contains tibialis anterior, EHL, EDL (dorsiflexion/toe extension), and the deep fibular nerve. It is the most common site of compartment syndrome. Classic sign: pain with passive plantarflexion (stretches anterior compartment muscles)."
},
{
"n": 30, "topic": "Leg β Muscles",
"q": "Which muscle is the PRIMARY invertor of the foot?",
"opts": ["A. Tibialis anterior", "B. Tibialis posterior", "C. Flexor hallucis longus", "D. Peroneus (fibularis) longus"],
"ans": "B",
"exp": "Tibialis posterior is the primary invertor of the foot. It also plantarflexes the ankle and supports the medial longitudinal arch (dysfunction β pes planus). Tibialis anterior also inverts but is primarily a dorsiflexor."
},
# SPINE
{
"n": 31, "topic": "Spine β Vertebrae",
"q": "Which cervical vertebra has a dens (odontoid process) and forms a pivot joint with C1?",
"opts": ["A. C1 (Atlas)", "B. C2 (Axis)", "C. C3", "D. C7 (Vertebra prominens)"],
"ans": "B",
"exp": "C2 (Axis) has the dens, which articulates with the anterior arch of C1, forming the atlantoaxial pivot joint responsible for ~50% of cervical rotation. C1 (Atlas) is ring-shaped with no body and no spinous process."
},
{
"n": 32, "topic": "Spine β Curves",
"q": "Which spinal curves are 'primary' (present at birth, concave anteriorly)?",
"opts": ["A. Cervical and lumbar", "B. Thoracic and sacral", "C. Cervical and thoracic", "D. Lumbar and sacral"],
"ans": "B",
"exp": "Primary (kyphotic) curves β thoracic and sacral β are present at birth and reflect the fetal C-shaped posture. Secondary (lordotic) curves β cervical (develops with head lifting ~3 months) and lumbar (develops with walking) β develop postnatally."
},
{
"n": 33, "topic": "Spine β Intervertebral Disc",
"q": "The nucleus pulposus is a remnant of which embryological structure?",
"opts": ["A. Notochord", "B. Neural crest", "C. Sclerotome", "D. Myotome"],
"ans": "A",
"exp": "The nucleus pulposus is derived from the notochord. It is rich in type II collagen and water (up to 90% in young adults), giving it a gel-like consistency that resists compressive forces."
},
{
"n": 34, "topic": "Spine β Disc Herniation",
"q": "Posterior-lateral disc herniation at L4βL5 most commonly compresses which nerve root?",
"opts": ["A. L4", "B. L5", "C. S1", "D. L3"],
"ans": "B",
"exp": "At each lumbar level, the nerve that exits (numbered nerve root) has already exited above the disc. A posterolateral herniation at L4βL5 compresses the L5 root (the descending root heading to the next foramen). L5βS1 disc herniates β S1 root."
},
{
"n": 35, "topic": "Spine β Ligaments",
"q": "Which spinal ligament lies between the laminae, is highly elastic (yellow colour), and when thickened contributes to spinal stenosis?",
"opts": ["A. Anterior longitudinal ligament", "B. Posterior longitudinal ligament", "C. Ligamentum flavum", "D. Supraspinous ligament"],
"ans": "C",
"exp": "Ligamentum flavum (Latin: yellow ligament) is rich in elastin, runs between adjacent laminae. With age/degeneration it hypertrophies and can narrow the spinal canal posteriorly β a common cause of lumbar spinal stenosis."
},
# DERMATOMES & REFLEXES
{
"n": 36, "topic": "Dermatomes",
"q": "Loss of sensation over the dorsum of the foot and lateral leg, with weakness of ankle dorsiflexion and great toe extension, indicates injury at which nerve root level?",
"opts": ["A. L3", "B. L4", "C. L5", "D. S1"],
"ans": "C",
"exp": "L5 dermatome: lateral leg, dorsum of foot, and medial 3 toes. L5 myotome: dorsiflexion (tibialis anterior), great toe extension (EHL), and hip abduction. L5 has no deep tendon reflex (unlike L4-knee jerk, S1-ankle jerk)."
},
{
"n": 37, "topic": "Reflexes",
"q": "Which nerve root mediates the Achilles tendon (ankle jerk) reflex?",
"opts": ["A. L3βL4", "B. L4βL5", "C. S1βS2", "D. L5βS1"],
"ans": "C",
"exp": "The ankle jerk (Achilles reflex) is mediated by S1βS2, testing the gastrocnemius/soleus via the tibial nerve. The knee jerk (patellar reflex) tests L3βL4, and the biceps reflex tests C5βC6."
},
# MIXED HIGH-YIELD
{
"n": 38, "topic": "Muscles β Architecture",
"q": "Which type of muscle pennation arrangement provides the greatest force production at the cost of range of motion?",
"opts": ["A. Parallel (strap) arrangement", "B. Multipennate arrangement", "C. Fusiform arrangement", "D. Circular (sphincter) arrangement"],
"ans": "B",
"exp": "Pennate muscles pack more fibers into a given volume (higher physiological cross-sectional area), generating greater force. Multipennate (e.g., deltoid) has the most fibers per volume. Parallel muscles (e.g., sartorius) have longer fibers and greater range of motion."
},
{
"n": 39, "topic": "Shoulder β Abduction",
"q": "Full overhead abduction (0β180Β°) of the arm requires a coordinated 'scapulohumeral rhythm.' The glenohumeral-to-scapular rotation ratio is approximately:",
"opts": ["A. 1:1", "B. 2:1", "C. 3:1", "D. 4:1"],
"ans": "B",
"exp": "Scapulohumeral rhythm: for every 3Β° of total abduction, 2Β° occur at the glenohumeral joint and 1Β° occurs as scapular upward rotation. This 2:1 ratio maintains optimal deltoid muscle length-tension throughout the arc."
},
{
"n": 40, "topic": "Knee β Locking Mechanism",
"q": "Which muscle 'unlocks' the knee from its fully extended (close-packed/screw-home) position by internally rotating the tibia?",
"opts": ["A. Biceps femoris", "B. Semimembranosus", "C. Popliteus", "D. Gastrocnemius"],
"ans": "C",
"exp": "In full extension, the tibia is externally rotated relative to the femur (screw-home mechanism). Popliteus internally rotates the tibia (or externally rotates the femur) to 'unlock' this position and initiate flexion. It is innervated by the tibial nerve."
},
]
# ββ Build PDF βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
doc = SimpleDocTemplate(
OUTPUT,
pagesize=A4,
rightMargin=2*cm, leftMargin=2*cm,
topMargin=2.2*cm, bottomMargin=2*cm,
title="Musculoskeletal Anatomy β 40 MCQs",
author="Orris Medical"
)
styles = getSampleStyleSheet()
# Custom styles
title_style = ParagraphStyle(
"TitleStyle", parent=styles["Title"],
fontSize=18, textColor=colors.HexColor("#1a3c5e"),
spaceAfter=4, leading=22
)
subtitle_style = ParagraphStyle(
"SubtitleStyle", parent=styles["Normal"],
fontSize=10, textColor=colors.HexColor("#5a7a9a"),
spaceAfter=2, alignment=TA_CENTER
)
topic_style = ParagraphStyle(
"TopicStyle", parent=styles["Normal"],
fontSize=8, textColor=colors.HexColor("#7f8c8d"),
fontName="Helvetica-Oblique", spaceAfter=2
)
question_style = ParagraphStyle(
"QuestionStyle", parent=styles["Normal"],
fontSize=11, fontName="Helvetica-Bold",
textColor=colors.HexColor("#1a1a2e"),
spaceAfter=4, leading=15
)
option_style = ParagraphStyle(
"OptionStyle", parent=styles["Normal"],
fontSize=10.5, fontName="Helvetica",
textColor=colors.HexColor("#2c3e50"),
spaceAfter=2, leftIndent=14, leading=14
)
answer_style = ParagraphStyle(
"AnswerStyle", parent=styles["Normal"],
fontSize=9.5, fontName="Helvetica",
textColor=colors.HexColor("#27ae60"),
spaceAfter=1, leading=13
)
exp_style = ParagraphStyle(
"ExpStyle", parent=styles["Normal"],
fontSize=9, fontName="Helvetica-Oblique",
textColor=colors.HexColor("#555555"),
spaceAfter=6, leftIndent=10, leading=13
)
ans_header_style = ParagraphStyle(
"AnsHeaderStyle", parent=styles["Heading2"],
fontSize=13, textColor=colors.HexColor("#1a3c5e"),
spaceAfter=6, spaceBefore=14
)
story = []
# Header
story.append(Paragraph("Musculoskeletal System Anatomy", title_style))
story.append(Paragraph("40 Multiple Choice Questions with Answers & Explanations", subtitle_style))
story.append(Paragraph("Source: THIEME Atlas of Anatomy | Gray's Anatomy for Students | Miller's Review of Orthopaedics", subtitle_style))
story.append(Spacer(1, 0.3*cm))
story.append(HRFlowable(width="100%", thickness=2, color=colors.HexColor("#1a3c5e")))
story.append(Spacer(1, 0.3*cm))
# Questions
story.append(Paragraph("SECTION A β QUESTIONS", ans_header_style))
story.append(Spacer(1, 0.2*cm))
for q in questions:
block = []
block.append(Paragraph(f"<font color='#7f8c8d'><i>{q['topic']}</i></font>", topic_style))
block.append(Paragraph(f"<b>Q{q['n']}. {q['q']}</b>", question_style))
for opt in q["opts"]:
block.append(Paragraph(opt, option_style))
block.append(Spacer(1, 0.25*cm))
story.append(KeepTogether(block))
story.append(Spacer(1, 0.5*cm))
story.append(HRFlowable(width="100%", thickness=1.5, color=colors.HexColor("#1a3c5e")))
story.append(Spacer(1, 0.3*cm))
# Answer Key table
story.append(Paragraph("SECTION B β ANSWER KEY", ans_header_style))
# Build answer key table
ak_data = [["Q", "Ans", "Q", "Ans", "Q", "Ans", "Q", "Ans"]]
row = []
for i, q in enumerate(questions):
row.append(f"Q{q['n']}")
row.append(q["ans"])
if (i + 1) % 4 == 0:
ak_data.append(row)
row = []
if row:
while len(row) < 8:
row.append("")
ak_data.append(row)
ak_table = Table(ak_data, colWidths=[1.2*cm]*8)
ak_table.setStyle(TableStyle([
("BACKGROUND", (0, 0), (-1, 0), colors.HexColor("#1a3c5e")),
("TEXTCOLOR", (0, 0), (-1, 0), colors.white),
("FONTNAME", (0, 0), (-1, 0), "Helvetica-Bold"),
("FONTSIZE", (0, 0), (-1, -1), 9.5),
("ALIGN", (0, 0), (-1, -1), "CENTER"),
("VALIGN", (0, 0), (-1, -1), "MIDDLE"),
("ROWBACKGROUNDS", (0, 1), (-1, -1), [colors.HexColor("#eaf4fb"), colors.white]),
("GRID", (0, 0), (-1, -1), 0.5, colors.HexColor("#bdc3c7")),
("ROWHEIGHT", (0, 0), (-1, -1), 18),
("FONTNAME", (1, 1), (1, -1), "Helvetica-Bold"),
("FONTNAME", (3, 1), (3, -1), "Helvetica-Bold"),
("FONTNAME", (5, 1), (5, -1), "Helvetica-Bold"),
("FONTNAME", (7, 1), (7, -1), "Helvetica-Bold"),
("TEXTCOLOR", (1, 1), (1, -1), colors.HexColor("#27ae60")),
("TEXTCOLOR", (3, 1), (3, -1), colors.HexColor("#27ae60")),
("TEXTCOLOR", (5, 1), (5, -1), colors.HexColor("#27ae60")),
("TEXTCOLOR", (7, 1), (7, -1), colors.HexColor("#27ae60")),
]))
story.append(ak_table)
story.append(Spacer(1, 0.6*cm))
# Explanations
story.append(HRFlowable(width="100%", thickness=1.5, color=colors.HexColor("#1a3c5e")))
story.append(Spacer(1, 0.3*cm))
story.append(Paragraph("SECTION C β DETAILED EXPLANATIONS", ans_header_style))
story.append(Spacer(1, 0.2*cm))
for q in questions:
block = []
block.append(Paragraph(f"<font color='#7f8c8d'><i>{q['topic']}</i></font>", topic_style))
block.append(Paragraph(f"<b>Q{q['n']}. {q['q']}</b>", question_style))
block.append(Paragraph(f"<b><font color='#27ae60'>β Correct Answer: {q['ans']}</font></b>", answer_style))
block.append(Paragraph(q["exp"], exp_style))
story.append(KeepTogether(block))
# Build
doc.build(story)
print(f"PDF saved to: {OUTPUT}")