An explainable lesson recommender
Create a Python program that asks about a learner’s experience, goal, Python knowledge and completed topics, then recommends a suitable next lesson.
Use clear if–then rules to recommend a learner’s next suitable Ai lesson and explain every decision.
Create a Python program that asks about a learner’s experience, goal, Python knowledge and completed topics, then recommends a suitable next lesson.
project-03-learning-path-recommender/
├── app.py
├── rules.py
├── test_recommender.py
├── README.md
└── project-checklist.txtCreate the learner profile, recommendation rules, command-line interface and tests.
Decide which limited information the rules need.
Place the ordered if–then rules inside rules.py.
def recommend_lesson(
experience: str,
goal: str,
knows_python: bool,
completed_topics: list[str],
) -> tuple[str, str]:
"""Recommend the next lesson and explain the decision."""
experience = experience.strip().lower()
goal = goal.strip().lower()
completed = {topic.strip().lower() for topic in completed_topics}
if experience == "beginner" and "ai foundations" not in completed:
return "Ai Foundations", "Start with the basic concepts first."
if not knows_python:
return "Python Foundations", "Python is needed for practical projects."
if goal == "machine learning" and "data preparation" not in completed:
return "Data Preparation", "Machine Learning requires clean data."
if goal == "machine learning":
return "Supervised Learning Basics", "You are ready for ML basics."
if goal == "generative ai":
return "Prompt Engineering", "Start with structured model interaction."
if goal == "computer vision":
return "Image Classification Basics", "Start with a core vision task."
return "Ai Applications Overview", "Explore the main application areas."The first matching rule returns the recommendation. Foundation and prerequisite checks should therefore appear before specialization rules.
Collect input safely and display both the lesson and reason.
from rules import recommend_lesson
experience = input("Experience level: ")
goal = input("Learning goal: ")
knows_python = get_yes_no("Do you know basic Python? Yes/No: ")
completed_text = input("Completed topics, separated by commas: ")
completed_topics = [topic.strip() for topic in completed_text.split(",") if topic.strip()]
lesson, reason = recommend_lesson(
experience, goal, knows_python, completed_topics
)
print("\nRecommended next lesson:", lesson)
print("Reason:", reason)python app.pyUse the supplied get_yes_no() function in the complete starter file so invalid answers are requested again.
Confirm that different profiles follow the intended rules.
Use assertions to check the recommendation function automatically.
from rules import recommend_lesson
lesson, _ = recommend_lesson(
experience="Beginner",
goal="Machine Learning",
knows_python=False,
completed_topics=["Ai Foundations"],
)
assert lesson == "Python Foundations"
lesson, _ = recommend_lesson(
experience="Beginner",
goal="Machine Learning",
knows_python=True,
completed_topics=["Ai Foundations", "Data Preparation"],
)
assert lesson == "Supervised Learning Basics"
print("All tests passed.")python test_recommender.pyAll tests passed.
I built a Rule-Based Learning Path Recommender using Python. The system collects a learner’s experience, goal, Python knowledge and completed topics, then applies explainable if–then rules to recommend the next lesson. I also added input validation, decision explanations and automated tests.