AI Computer Science Academy · Faisalabad

AI & Prompt Engineering

A working rule-based bot

Task 31 of 56 Python Content and quality
All tasks
Read first Task 31

A working rule-based bot

Now put the pieces together: normalise the question, match against the FAQ, fall back to the phone number. This is exactly how the academy assistant answers before a model is involved.

Task

What does the bot do when nothing matches?

The editor already contains a starting point. Change it until every check passes — the Next task button unlocks when it does.

What you start with
FAQ = {
    'fee': 'Python costs Rs 11,667 per month.',
    'timing': 'Classes run Monday to Saturday, 10:00 to 20:00.',
    'admission': 'Bring your CNIC copy and pick a timing.',
}
FALLBACK = 'Please call +92 325 8000848 and we will help.'

def reply(question):
    q = question.lower()
    for key in FAQ:
        if key in q:
            return FAQ[key]
    return FALLBACK

for q in ['What is the fee?', 'timing please', 'Do you teach cooking?']:
    print(q, '=>', reply(q))
Python 1 automatic check Content and quality
Code editor Ctrl + Enter runs
Run your code to see the output and the checks.
Your result

Submit your code to see results

Write your code in the middle column and press Run code.

Checks on this task:

  • Check 1

Track progress

0 of 56 tasks complete

Next task unlocks when every check passes.

Sign in to keep your code and certificates.

Next task (pass every check first)