Untitled

 avatar
unknown
plain_text
a month ago
2.8 kB
2
Indexable
# Importing necessary libraries
import random

class AITeacher:
    def __init__(self, subject):
        self.subject = subject
        self.topics = {
            "math": ["addition", "subtraction", "multiplication", "division"],
            "science": ["planets", "photosynthesis", "gravity", "electricity"],
            "history": ["world wars", "ancient civilizations", "renaissance", "industrial revolution"],
            "literature": ["poetry", "prose", "drama", "novels"]
        }
        self.questions = {
            "math": {
                "addition": lambda: f"What is {random.randint(1, 10)} + {random.randint(1, 10)}?",
                "subtraction": lambda: f"What is {random.randint(10, 20)} - {random.randint(1, 10)}?",
                "multiplication": lambda: f"What is {random.randint(1, 10)} * {random.randint(1, 10)}?",
                "division": lambda: f"What is {random.randint(10, 100)} / {random.randint(1, 10)}?"
            },
            "science": {
                "planets": "What is the largest planet in our solar system?",
                "photosynthesis": "What do plants produce during photosynthesis?",
                "gravity": "Who discovered gravity?",
                "electricity": "What is the unit of electrical resistance?"
            },
            "history": {
                "world wars": "In which year did World War II begin?",
                "ancient civilizations": "Which civilization built the pyramids?",
                "renaissance": "Who painted the Mona Lisa?",
                "industrial revolution": "In which century did the Industrial Revolution begin?"
            },
            "literature": {
                "poetry": "Who wrote 'The Raven'?",
                "prose": "What is the primary difference between prose and poetry?",
                "drama": "Who is the author of 'Romeo and Juliet'?",
                "novels": "What is the title of the first novel ever written?"
            }
        }

    def greet(self):
        return f"Hello! I am your AI teacher for {self.subject}. Let's start learning!"

    def teach_topic(self, topic):
        if topic in self.topics.get(self.subject, []):
            return f"Today's topic is: {topic}. Here's a question for you: {self.ask_question(topic)}"
        else:
            return "Sorry, I can't teach this topic. Please choose another."

    def ask_question(self, topic):
        if self.subject in self.questions and topic in self.questions[self.subject]:
            question = self.questions[self.subject][topic]
            return question() if callable(question) else question
        else:
            return "No questions available for this topic."

# Example usage
teacher = AITeacher("math")
print(teacher.greet())
print(teacher.teach_topic("addition"))
Leave a Comment