🐸

The FAQ Bot

Python Basicspython-basics-37-the-faq-bot
Reward: 100 XP
|

The FAQ Bot

Welcome to Customer Service.

In the Digital Forest, you might have consulted a Magic Book. In the Real World, businesses need to answer thousands of customers instantly. They use Chatbots.

The Problem: Customers ask the same questions over and over ("Where is my refund?", "Are you open?"). The Goal: Build a robot that matches "Keywords" to "Answers".

Magic vs. Reality

Real chatbots listen to input().

But since you are coding in a Browser Simulation, we cannot block the script to wait for your typing. Instead, we will simulate a conversation by processing a list of messages.

The Tools

# Key = What user asks, Value = What bot says
knowledge = {
  "hi": "Hello there!",
  "bye": "See you later!"
}

print(knowledge["hi"])  # "Hello there!"
# Instead of 'while True', we iterate over a list
incoming_messages = ["hi", "bye", "refund"]

for message in incoming_messages:
  if message == "hi":
      print("Bot: Hello!")

Your Task

You are building the FAQ Bot for HoppyShop.

The system will feed you a list of customer queries: queries = ["hours", "refund", "shipping", "joke"].

1
Knowledge Base

Create a dictionary called responses. Add these keys:

  • "refund" -> "We offer full refunds within 30 days."
  • "hours" -> "We are open 24/7."
  • "shipping" -> "Free shipping on all orders!"
2
Simulation

Write a for loop to iterate through the queries list.

3
Reply

Inside the loop, check if the message is in your responses dictionary.

  • If Yes: Print the matching value.
  • If No: Print "I don't understand."
Suggested Solution
Expand
Solution:

This simulation proves your logic works. In a real Python terminal, you would simply swap the for loop with while True and input().

queries = ["hours", "refund", "shipping", "joke"]

responses = {
  "refund": "We offer full refunds within 30 days.",
  "hours": "We are open 24/7.",
  "shipping": "Free shipping on all orders!"
}

print("Bot: System Online...")

for message in queries:
  print(f"User: {message}")
  
  if message in responses:
      print("Bot:", responses[message])
  else:
      print("Bot: I don't understand.")
Loading...
Terminal
Terminal
Ready to run...