Kunafalol commited on
Commit
58b5b2b
·
verified ·
1 Parent(s): ade7baa

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +16 -27
README.md CHANGED
@@ -17,49 +17,38 @@ license: openrail
17
  ---
18
  import random
19
 
20
-
21
- subject_questions = {
22
- 'math': [
23
  {'question': 'What is the value of x in the equation 2x + 5 = 11?', 'answer': '6'},
24
  {'question': 'What is the formula for the area of a circle?', 'answer': 'A = πr^2'},
25
  {'question': 'What is the value of sin(30°)?', 'answer': '0.5'}
26
  ],
27
- 'science': [
28
  {'question': 'What is the process by which plants make their own food?', 'answer': 'photosynthesis'},
29
  {'question': 'What is the largest planet in our solar system?', 'answer': 'Jupiter'},
30
  {'question': 'What is the smallest bone in the human body?', 'answer': 'stapes'}
31
  ],
32
- 'english': [
33
  {'question': 'Who wrote the book "To Kill a Mockingbird"?', 'answer': 'Harper Lee'},
34
  {'question': 'What is the definition of the word "persuade"?', 'answer': 'to convince someone to do something'},
35
  {'question': 'What is the title of the first book in the Harry Potter series?', 'answer': 'Harry Potter and the Philosopher\'s Stone'}
36
  ]
37
  }
38
 
39
-
40
  def get_ai_bot_response(subject, question):
41
- # Check if the subject is valid
42
- if subject not in subject_questions:
 
 
 
 
43
  return 'Invalid subject. Please try again.'
44
 
45
- # Check if the question is valid
46
- for q in subject_questions[subject]:
47
- if q['question'] == question:
48
- return q['answer']
49
-
50
- # If the question is not found, return a default message
51
- return 'Sorry, I couldn\'t find the answer to that question. Please try again.'
52
-
53
-
54
- def get_Brainzilla_ai_bot_response():
55
- # Get a random subject
56
- subject = random.choice(list(subject_questions.keys()))
57
-
58
- # Get a random question from the subject
59
- question = random.choice(subject_questions[subject])
60
-
61
- # Return the AI bot's response
62
  return get_ai_bot_response(subject, question['question'])
63
 
64
-
65
- print(get_Brainzilla_ai_bot_response())
 
17
  ---
18
  import random
19
 
20
+ subjects = {
21
+ 'Math': [
 
22
  {'question': 'What is the value of x in the equation 2x + 5 = 11?', 'answer': '6'},
23
  {'question': 'What is the formula for the area of a circle?', 'answer': 'A = πr^2'},
24
  {'question': 'What is the value of sin(30°)?', 'answer': '0.5'}
25
  ],
26
+ 'Science': [
27
  {'question': 'What is the process by which plants make their own food?', 'answer': 'photosynthesis'},
28
  {'question': 'What is the largest planet in our solar system?', 'answer': 'Jupiter'},
29
  {'question': 'What is the smallest bone in the human body?', 'answer': 'stapes'}
30
  ],
31
+ 'English': [
32
  {'question': 'Who wrote the book "To Kill a Mockingbird"?', 'answer': 'Harper Lee'},
33
  {'question': 'What is the definition of the word "persuade"?', 'answer': 'to convince someone to do something'},
34
  {'question': 'What is the title of the first book in the Harry Potter series?', 'answer': 'Harry Potter and the Philosopher\'s Stone'}
35
  ]
36
  }
37
 
 
38
  def get_ai_bot_response(subject, question):
39
+ try:
40
+ for q in subjects[subject]:
41
+ if q['question'].lower() == question.lower():
42
+ return q['answer']
43
+ return 'Sorry, I couldn\'t find the answer to that question. Please try again.'
44
+ except KeyError:
45
  return 'Invalid subject. Please try again.'
46
 
47
+ def get_random_ai_bot_response():
48
+ subject = random.choice(list(subjects.keys()))
49
+ questions = subjects[subject]
50
+ question = random.choice(questions)
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  return get_ai_bot_response(subject, question['question'])
52
 
53
+ brainzilla1_response = get_random_ai_bot_response()
54
+ print(brainzilla1_response)