
# ==========================================
# FACTS: Knowledge Base
# ==========================================

# Facts: students
students = [
    "budi",
    "sari",
    "dewi"
]

# Facts: students and the courses they study
studies = [
    ("budi", "ai"),
    ("sari", "ml"),
    ("dewi", "ai")
]

# Facts: teachers and the courses they teach
teaches = [
    ("media", "ai"),
    ("rahmadya", "ml")
]


# ==========================================
# RULE: taught_by(X, Z)
# If X is a student,
# X studies course Y,
# and Z teaches course Y,
# then X is taught by Z.
# ==========================================

def taught_by():
    results = []

    for student in students:
        for person, course in studies:
            if student == person:
                for teacher, taught_course in teaches:
                    if course == taught_course:
                        results.append((student, teacher))

    return results


# ==========================================
# QUERY: Display all inference results
# ==========================================

for student, teacher in taught_by():
    print(student + " diajar oleh " + teacher)
