File size: 1,819 Bytes
1e5eaff 92bd55d ade7baa 92bd55d ade7baa 92bd55d af6b84f 58b5b2b 312024b 58b5b2b 312024b 58b5b2b 312024b 58b5b2b 312024b af6b84f 58b5b2b 312024b af6b84f 58b5b2b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | ---
language:
- en
- ur
- ar
- bn
library_name: transformers
tags:
- '#study'
- '#grade7'
- '#grade8'
- '#grade9'
- education
- '#ai'
- '#STEM'
license: openrail
---
import random
subjects = {
'Math': [
{'question': 'What is the value of x in the equation 2x + 5 = 11?', 'answer': '6'},
{'question': 'What is the formula for the area of a circle?', 'answer': 'A = πr^2'},
{'question': 'What is the value of sin(30°)?', 'answer': '0.5'}
],
'Science': [
{'question': 'What is the process by which plants make their own food?', 'answer': 'photosynthesis'},
{'question': 'What is the largest planet in our solar system?', 'answer': 'Jupiter'},
{'question': 'What is the smallest bone in the human body?', 'answer': 'stapes'}
],
'English': [
{'question': 'Who wrote the book "To Kill a Mockingbird"?', 'answer': 'Harper Lee'},
{'question': 'What is the definition of the word "persuade"?', 'answer': 'to convince someone to do something'},
{'question': 'What is the title of the first book in the Harry Potter series?', 'answer': 'Harry Potter and the Philosopher\'s Stone'}
]
}
def get_ai_bot_response(subject, question):
try:
for q in subjects[subject]:
if q['question'].lower() == question.lower():
return q['answer']
return 'Sorry, I couldn\'t find the answer to that question. Please try again.'
except KeyError:
return 'Invalid subject. Please try again.'
def get_random_ai_bot_response():
subject = random.choice(list(subjects.keys()))
questions = subjects[subject]
question = random.choice(questions)
return get_ai_bot_response(subject, question['question'])
brainzilla1_response = get_random_ai_bot_response()
print(brainzilla1_response) |