Untitled
unknown
plain_text
9 months ago
4.3 kB
8
Indexable
# Simple Python program to generate nursing-themed flashcards and tests from pasted PDF text.
# This script assumes you paste the extracted text from your PDF (use tools like online PDF-to-text converters if needed).
# It processes the text, extracts key sentences/phrases, and creates flashcards in a Quizlet-like format (CSV for easy import).
# For tests, it generates multiple-choice questions based on the content.
# Nursing theme: Flashcards are formatted with categories like "Assessment," "Intervention," "Nursing Diagnosis," etc., to aid study.
import re
import random
def extract_key_points(text):
# Split text into sentences and filter for potential flashcard material (e.g., definitions, facts).
sentences = re.split(r'[.!?]', text)
key_points = [s.strip() for s in sentences if len(s.strip()) > 10 and not s.lower().startswith(('table', 'figure', 'reference'))]
return key_points[:50] # Limit to 50 for manageability; adjust as needed.
def generate_flashcards(key_points):
# Create Q&A flashcards. For each key point, generate a question and answer.
flashcards = []
for point in key_points:
# Simple question generation: Turn statement into a question.
question = f"What is the nursing consideration for: {point[:100]}...?" # Truncate for brevity.
answer = point
# Add nursing theme: Categorize randomly or based on keywords.
category = "General Nursing" # Default
if "assessment" in point.lower():
category = "Assessment"
elif "intervention" in point.lower() or "monitor" in point.lower():
category = "Intervention"
elif "diagnosis" in point.lower():
category = "Nursing Diagnosis"
flashcards.append({"question": question, "answer": answer, "category": category})
return flashcards
def generate_test(flashcards, num_questions=10):
# Create a simple multiple-choice test from flashcards.
test = []
for i in range(min(num_questions, len(flashcards))):
card = flashcards[i]
# Generate options: Correct answer + 3 random distractors from other cards.
correct = card["answer"]
distractors = [f["answer"] for f in flashcards if f != card][:3]
options = [correct] + distractors
random.shuffle(options)
test.append({
"question": card["question"],
"options": options,
"correct": correct
})
return test
def output_quizlet_csv(flashcards, filename="nursing_flashcards.csv"):
# Output flashcards in CSV format for Quizlet import (columns: Term, Definition, Category).
with open(filename, "w") as f:
f.write("Term,Definition,Category\n")
for card in flashcards:
f.write(f'"{card["question"]}","{card["answer"]}","{card["category"]}"\n')
print(f"Flashcards saved to {filename}. Import into Quizlet by uploading the CSV.")
def output_test(test):
# Print the test to console for quick review.
print("\n--- Nursing Test (Multiple Choice) ---")
for i, q in enumerate(test, 1):
print(f"{i}. {q['question']}")
for j, opt in enumerate(q['options'], 1):
print(f" {chr(64+j)}. {opt[:100]}...") # A, B, C, D
print(f" Correct: {q['correct'][:100]}...\n")
# Main function: Paste your PDF text here as a string.
if __name__ == "__main__":
# Example: Replace this with your pasted PDF text.
pdf_text = """
Verapamil is a calcium channel blocker used in nursing for hypertension management.
Monitor for effects on SA and AV nodes to prevent bradycardia.
Assessment includes checking ECG for PR interval prolongation.
Intervention: Administer IV slowly and observe for hypotension.
Nursing diagnosis: Risk for decreased cardiac output related to nodal effects.
"""
key_points = extract_key_points(pdf_text)
flashcards = generate_flashcards(key_points)
test = generate_test(flashcards)
# Output flashcards for Quizlet.
output_quizlet_csv(flashcards)
# Output test for study.
output_test(test)
print("Study tip: Review flashcards daily, focus on categories. For your exam in 3 days, quiz yourself with the test output. Good luck!")
Editor is loading...
Leave a Comment