Return to site

Build an AI Chatbot in Python

Educators & parents: You can do this Hour of Code Activity as a class or students can work on it independently. If you have any questions or need help, email info@codespeaklabs.com.

 

Special thanks to Alans, the creator of this project and tutorial. Alans was an inaugural member of the Abretech program for multilingual high school students.

Hi, I’m Alans. I’m a High School Junior in the AbreTech program. I’m excited to teach you the basics of Artificial intelligence (also known as AI). In this tutorial you will code a mini version of an AI chatbot with a back up system.

We'll use the programming language Python to code a program that responds like a human, similar to Artificial intelligence. Your program will ask the user for information and respond in a way that uses that information. The computer saves the information users provide to personalize its responses, like Apple’s Siri or Amazon’s Alexa.

What we'll cover: 

  • While loops
  • If statements
  • Input variables
  • Back up systems that make use of loops and length to track errors
  • Organization
  • Execution/testing
broken image

Part 1: Setup Project

We are going to clear the editor and work on the beginning of the code.

Part 2: Code the Game

Let's code the game and create the backup systems.

Part 3: Debugging

Test the code for any errors or bugs, and make it more human-like, as well as ensure it works as expected, and explain it to the viewer.

Congratulations on successfully completing a mini AI chatbot with python! As a bonus, you can implement a new questions like "What would you like to be in the future?"

Tip: Look at how we implemented the goals section.

Want to go beyond Hour of Code? Click here to learn to program a Strong Password Generator in Python.

If you had fun, check out our YouTube channel for more free coding projects like these! Go to youtube.com/codespeaklabs.