Project 22 of 35  ·  Scratch Programming  ·  Module 1
Module 1

Chatbot

Program an interactive chatbot that understands keywords and remembers the user's name.

🍓  Open on Raspberry Pi Projects  ↗ Opens the official Raspberry Pi Foundation project — includes starter files and full step-by-step guide

What You Will Build

Program an interactive chatbot that understands keywords and remembers the user's name. Follow the guide below to build the project, then open the official Raspberry Pi page for starter files, worked examples and extra help.

🍓 This project is on the Raspberry Pi Foundation website. Click the orange button above to access the full guide, starter Scratch project and extension activities on projects.raspberrypi.org.

What You Will Learn

  • Use ask and wait to collect user input into an answer variable
  • Use contains to check for keywords in the user's reply
  • Store the user's name and use it in personalised responses
  • Build a conversational loop that keeps asking after each reply
  • Handle unrecognised input gracefully

Step-by-Step Guide

  • 1Add a friendly character sprite.
  • 2On start: ask [What's your name?] and wait. Set name to answer.
  • 3Say join [Hello, ] (join (name) [! Ask me anything.]).
  • 4Add a forever loop: ask [What would you like to know?] and wait.
  • 5Store answer in a variable called input.
  • 6Add if <(input) contains [hello]>: say Hello there!.
  • 7Add 10+ keyword checks: joke, weather, name, age, help, bye, colour, food, time, fun.
  • 8For each: a different personalised response using the name variable.
  • 9Add else: say [I don't understand that yet. Try: joke, weather, help].
  • 10When input contains [bye]: say [Goodbye, (name)!] and stop all.

Extension Challenges

Finished the main project? Push further:

  • Add a mood system: rude words trigger a different response.
  • Add a quiz the chatbot can run when the user says quiz.
  • Add the Translate extension to let the chatbot respond in a different language.