TGViewer
Python Projects & Free Books Python Projects & Free Books @pythonfreebootcamp · 40.7K subscribers
Post #1330 3.24K
Convert any long article or PDF into a test in a couple of seconds!

Mini-service: we take the text of the article (or extract it from PDF), send it to GPT and receive a set of test questions with answer options and a key.

First, we load the text of the material:
# article_text — this is where we put the text of the article
with open("article.txt", "r", encoding="utf-8") as f:
    article_text = f.read()

# for PDF, you can extract the text in advance with any library (PyPDF2, pdfplumber, etc.)


Next, we ask GPT to generate a test:
prompt = (
    "You are an exam methodologist."
    "Based on this text, create 15 test questions."
    "Each question is in the format:\n"
    "1) Question text\n"
    "A. Option 1\n"
    "B. Option 2\n"
    "C. Option 3\n"
    "D. Option 4\n"
    "Correct answer: <letter>."
    "Do not add explanations and comments, only questions, options, and correct answers."
)
response = client.chat.completions.create(
    model="gpt-4o",
    messages=[
        {"role": "system", "content": prompt},
        {"role": "user", "content": article_text}
    ])
print(response.choices[0].message.content.strip())


✅ Suitable for online courses, educational centers, and corporate training — you immediately get a ready-made bank of tests from any article.
  • 👍 4
More from @pythonfreebootcamp
  1. Oct 2, 2026Data Analytics A-Z
  2. Sep 25, 2026🎯 GigaChat 3.5 Reasoning: 5 Key Features 1️⃣ Advanced Reasoning: Explores multiple step-b…
  3. Sep 19, 2026Let’s dive into our first mini project using Python: Project 1: Number Guessing Game 🎯 Go…
  4. Sep 14, 2026Learn AI for Free in 2026👇 1/ Kaggle Learn: https://www.kaggle.com/learn 2/ Anthropic Lea…
  5. Aug 7, 2026Roadmap to become a data analyst 1. Foundation Skills: •Strengthen Mathematics: Focus on s…
  6. Jul 31, 2026🐍 Python Roadmap 1️⃣ Basics: 📝📜 Syntax, Variables, Data Types 2️⃣ Control Flow: 🔄🤖 If…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →