Project 34: Flashcard Forge 🗂️¶
Difficulty: 🟡 Intermediate
Run cells top to bottom. Each step builds on the previous one and saves real files under outputs/flashcard_forge/.
In [1]:
# Install dependencies for this project (safe to re-run)
import sys
!{sys.executable} -m pip install pillow numpy matplotlib wordcloud qrcode[pil] python-barcode fpdf2 jinja2 folium plotly pandas scipy ipywidgets -q
Skipping pip install (already installed)
In [2]:
# Interactive Jupyter setup — run this cell first
%matplotlib inline
from pathlib import Path
from IPython.display import display, Image as IPImage, HTML, Markdown, Audio, IFrame
OUTPUT_DIR = Path("outputs") / "flashcard_forge"
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
print(f"✅ Outputs folder: {OUTPUT_DIR.resolve()}")
✅ Outputs folder: C:\Users\Hansel Yan\Projects\CodeItAll\outputs\flashcard_forge
Step 1 — Build the deck¶
In [3]:
import json
# 🎛️ TWEAK THESE
CARDS = [
{"front": "What does len() do?", "back": "Returns the number of items in a container."},
{"front": "List vs tuple?", "back": "Lists are mutable; tuples are immutable."},
{"front": "What is a dict?", "back": "A mapping of keys to values."},
{"front": "What is a path?", "back": "A filesystem location — use pathlib.Path."},
{"front": "What is pip?", "back": "Python's package installer."},
]
deck_path = OUTPUT_DIR / "flashcards.json"
deck_path.write_text(json.dumps(CARDS, indent=2), encoding="utf-8")
print(f"Deck saved with {len(CARDS)} cards → {deck_path}")
Deck saved with 5 cards → outputs\flashcard_forge\flashcards.json
Step 2 — Quiz + printable sheet¶
In [4]:
import random
# 🎛️ TWEAK THESE
ROUNDS = 3
SEED = 2
random.seed(SEED)
cards = json.loads(deck_path.read_text(encoding="utf-8"))
sample = random.sample(cards, k=min(ROUNDS, len(cards)))
print("QUIZ TIME (answers revealed)\n")
lines = ["CodeItAll Flashcard Forge", "=" * 28, ""]
for i, card in enumerate(sample, 1):
print(f"Q{i}: {card['front']}")
print(f"A{i}: {card['back']}\n")
lines += [f"Q{i}: {card['front']}", f"A{i}: {card['back']}", ""]
sheet = OUTPUT_DIR / "flashcard_sheet.txt"
sheet.write_text("\n".join(lines), encoding="utf-8")
print(f"Printable sheet → {sheet}")
QUIZ TIME (answers revealed) Q1: What does len() do? A1: Returns the number of items in a container. Q2: What is pip? A2: Python's package installer. Q3: What is a path? A3: A filesystem location — use pathlib.Path. Printable sheet → outputs\flashcard_forge\flashcard_sheet.txt