Lesson 7.4: Debugging Chatbots

Today’s Goals

  • Learn to identify and fix common chatbot bugs
  • Practice debugging strategies with user input
  • Improve chatbot reliability

Warm-Up Question

  • What’s the funniest bug you’ve ever seen in a program?

Common Chatbot Bugs

  • Case sensitivity: Yes vs yes
  • Missing conditions: input doesn’t match any branch
  • Logic errors: wrong response chosen
  • Infinite loops: chatbot never stops

Example Bug

user_input = input("Do you like pizza? ")
if user_input == "yes":
    print("Yay pizza!")
elif user_input == "no":
    print("More for me!")

Problem: typing Yes or YES doesn’t work.

Fix with .lower()

user_input = input("Do you like pizza? ").lower()
if user_input == "yes":
    print("Yay pizza!")
elif user_input == "no":
    print("More for me!")
else:
    print("I didn’t understand that.")

Debugging Strategies

  • Add print statements to trace logic
  • Test multiple inputs, not just one
  • Always include an else case

Class Activity

  • Take your chatbot from last time
  • Intentionally break it (remove a condition, make a typo)
  • Swap with a partner and debug each other’s chatbot

Student Challenge

  • Add input validation to prevent crashes
  • Ensure your chatbot always responds politely, even with nonsense input

Wrap-Up

  • Debugging makes chatbots flexible and user-friendly
  • Next time: Creative Project Proposal & Brainstorm