teachComputing
  • Home
  • AI
    • AI Literacy >
      • AI Alliteration
      • Describing Monsters
      • Dystopian writing
      • Bringing literacy to life with AI
      • AI Literacy Prompts
    • AI Computing >
      • AI Computing Lessons >
        • Make me happy
        • Chatting Robot
        • Supervised Learning
        • Fooled
        • Socratic Debate
        • Moral Machine
      • AI Coding Strategies
      • AI Computing Prompts
    • AI Prompts
  • Teaching & Learning
    • Wellbeing
    • Blog
    • Humour >
      • Teacher Humour
      • Teacher Humor
    • PLN Challenge >
      • Covering your backside
      • Online Privacy
      • Twitter Challenge >
        • Twitter All Star
        • Challenge 1
        • Challenge 2
        • Challenge 3
        • Tips for staying safe on Twitter
        • Tips for hosting Edu Twitter Chats
        • Tips for taking part in Twitter chats
        • It's all about the hashtag! Essential chats for educators
        • How to storify a chat
        • How to schedule Tweets
        • Twitter Lists
        • NT2tEU
      • Facebook Challenge >
        • Challenge 4
        • Challenge 5
        • Challenge 6
        • Tips for staying safe on Facebook
      • Google Challenge >
        • Challenge 7
        • Challenge 8
        • Challenge 9
      • Pinterest Challenge >
        • Challenge 10
        • Challenge 11
        • Challenge 12
        • Tips for using Pinterest
      • Blog Challenge >
        • Challenge 13
        • Challenge 14
        • Challenge 15
        • How to create a classroom blog
      • Staffrm Challenge >
        • Challenge 16
        • Challenge 17
        • Challenge 18
      • Skype Challenge >
        • Challenge 19
        • Challenge 20
        • Challenge 21
      • Edmodo Challenge >
        • Challenge 22
        • Challenge 23
        • Challenge 24
      • TeachMeet Challenge >
        • Challenge 25
        • Challenge 26
        • Challenge 27
      • In-school challenge >
        • Challenge 28
        • Challenge 29
        • Challenge 30
      • 30 ways to grow your PLN
    • Tools for Teachers >
      • Web 2.0 >
        • Top 10 Web 2.0 Tools
        • Classroom Response Tools
      • Quiz Tools
      • Classroom Management Tools
      • Software >
        • Media Conversion Tools
        • Application Software
      • Multimedia >
        • Free Music
    • BYOD
    • Digital Leaders >
      • Digital Leaders Blog >
        • DL Archive
      • DL Tips
      • Quotes
      • Links
    • Flipped Learning >
      • Flipped Classroom vs. Blended Classroom
    • Gamification >
      • Gamification vs. Game Based Learning vs. Game Design
    • School Closures
    • Game Based Learning >
      • Minecraft >
        • Minecraft in Education
        • Minecraft Lesson Ideas
        • Minecraft Literacy
        • Real Life Minecraft
        • Minecraft Top Tips
        • Minecraft Coding Tutorials >
          • Minecraft Code Builder Setup
          • Minecraft Code: Walking on Air
          • Minecraft Code: Hello World
          • Minecraft Code: Functions
          • Minecraft Code: Rainbow
          • Minecraft Code: Skyscraper
          • Minecraft Pixel Art
    • The magic of >
      • The magic of Computing
      • The magic of Maths
      • The magic of Science
      • The magic of Literacy
    • Road2e2
    • T&L Blog
  • Computing
    • Computing Blog >
      • GCSE Computer Science
      • General
    • Teaching Computer Science >
      • CPD >
        • Blocks to Code
        • Tutorials >
          • How to embed Flash into PowerPoint
          • How to embed YouTube videos in to PowerPoint
          • How to create a wiki
          • How to create a classroom blog
      • Schemes of Work
      • Programming Resources
      • Theory
      • Posters
      • Festive Computing Activities
      • FLOPPYS 2020
      • FLOPPYS 2021
      • FLOPPYS 2022
      • Game Design
      • App Creation
    • Theory Lessons >
      • Theory Tests
      • Computer Hardware >
        • Input / Output
        • CPU
        • LMC
        • Storage Devices
        • Memory (RAM / ROM)
        • Hardware
      • Binary Lessons >
        • Units of Data
        • Binary Representation
        • Binary Representation of Images
        • Binary Representation of Images (Festive)
        • Binary Representation of Characters
        • Binary Representation of Sound
        • Binary Representation of Instructions
        • Binary Addition
        • Hexadecimal
      • Software >
        • Operating System
        • Types of Software
        • Utility Software
      • Programming >
        • Flowcharts
      • Computational Thinking >
        • Data Science
    • Digital Literacy >
      • Social Media (Good or Bad thing?)
      • Cyberbullying
      • Staying Safe Online
    • ICT Strand >
      • Fake News Project >
        • Fake News 1
        • Fake News 2
        • Fake News 3
        • Fake News 4
        • Fake News 5
      • Spreadsheet Modelling
      • Superhero Movie Trailer
      • PowerPoint Task
      • Digital Imaging
      • Paint 3D Tutorial
    • Programming Lessons >
      • Scratch >
        • Festive Scratch >
          • Music Festive with Scratch
          • Turtle Snowflakes
          • What's your elf name
          • Secret Santa
        • Making music with Scratch
        • Sorting Hat Lesson
        • Turtle Time
        • Superhero name generator
        • Compliment Generator
        • Magic 8 ball
      • Python >
        • Chatbot
        • Coding Golf
        • Turtle Time >
          • Turtle Instructions
        • Magic 8 ball
        • Python Mad Libs
        • Rock Paper Scissors
        • Shakespearean Insult Generator >
          • Shakespearean Insult Generator Part 2
        • Compliment generator
        • Sorting Hat
        • Superhero name generator
        • Cards Against
        • Guess the word
        • Guess the number
        • Festive Python >
          • What's your elf name
          • Secret Santa
          • Turtle Snowflakes
      • Little Man Computer
      • Hour of Code >
        • Hour of Code Music
        • Python Tutorials
        • HoC 8-Bit Challenge
        • Music MicroPython (Festive)
      • Raspberry Pi >
        • Networking the Pi
        • Minecraft Pi
        • Harry Potter Sorting Hat >
          • Harry Potter Sorting Hat (GPIO)
        • Raspberry Pi LTSP (Networked Classroom)
        • Astro Pi
    • Homeschooling
    • Remote Learning >
      • Fun Python Tutorials
      • Python Tutorials >
        • Chatbot Tutorial
        • Dice Roll
        • Turtle Tutorial
        • Magic 8 ball
        • Sorting Hat
        • Rock Paper Scissors Tutorial
        • Cards Against
        • Python Mad Libs
        • Shakespearean Insult Generator >
          • Shakespearean Insult Generator Part 2
        • Guess the word
        • Guess the number
        • Superhero name generator
        • Compliment generator
        • Festive Python Tutorials >
          • What's your elf name
          • Secret Santa
          • Turtle Snowflakes
      • Scratch Tutorials >
        • Sorting Hat
        • What's your superhero name
        • Turtle Time Tutorial
        • Compliment Generator
        • Magic 8 Ball
        • Festive Scratch Tutorials >
          • Festive Music with Scratch
          • Secret Santa Scratch Tutorial
          • Turtle Snowflakes Tutorial
          • What's your elf name
    • Revision >
      • Data Representation >
        • Binary Representation of Images
        • Binary Representation of Sound
  • 21 Things
    • 21 Things To Try >
      • ConnectEd
      • Social Media >
        • Twitter
        • Pinterest
        • Facebook Groups
        • Facebook Pages
        • Google+ Communities
        • Staffrm
        • Edmodo
        • Mystery Skype
        • Blogging
        • Classroom Blogging
      • Gamification
      • Flipped Classroom
      • Breakout Edu
      • Edu Podcasts
      • Jar of Awesome
      • TeachMeet
      • Team Teaching
      • Mixed Reality
      • Digital Leaders
      • Genius Hour
      • Sketchnoting
    • Computing >
      • CS 20
      • Code Golf
      • PRIMM
      • Under The Hood
      • Unplugged
      • Podcasts
      • Facebook Groups CS
      • Flipped Classroom CS
      • Teach with Magic
      • Socratic Debate
      • Coding Music
    • 21 Things Keep Fit >
      • 20 Health Hacks
      • Home Health Hacks
    • 21 Things PLN >
      • Edmodo
      • Twitter
      • Reply to a blog
      • Skype
      • Cofee Edu
      • Pinterest
      • Reach out
      • Conferences
      • Instagram
      • Ning
      • MEC
      • Voxer
      • LinkedIn
  • Microbit
    • Physical Computing >
      • micro:bit LEDs
      • micro:bit PIR
      • micro:bit Servo
      • micro:bit Temp
      • micro:bit LDR
      • micro:bit Moisture
      • micro:bit RGB LEDs
      • micro:bit HC-SR04 3v3
      • micro:bit HC-SR04 5v
      • micro:bit Push button
      • micro:bit Potentiometer
      • micro:bit Piezo
    • Music >
      • Music Festive
    • Festive Projects
    • Projects >
      • Music
      • Music MicroPython
      • Servo Animals
    • Lessons >
      • Magic 8 Ball
      • Harry Potter Sorting Hat
    • Quick Start Guide
    • Microbit Simulator
  • #100 Ideas
    • Testimonials
    • Competition >
      • Competition 2
    • Worksheets
    • Bonus Ideas >
      • What's your elf name
      • Make me happy
      • Guess the word
      • Cards Against Humanities
      • Compliment generator
      • Data Science
    • Curriculum
    • ISTE
    • CSTA
  • About
    • Privacy
  • Home
  • AI
    • AI Literacy >
      • AI Alliteration
      • Describing Monsters
      • Dystopian writing
      • Bringing literacy to life with AI
      • AI Literacy Prompts
    • AI Computing >
      • AI Computing Lessons >
        • Make me happy
        • Chatting Robot
        • Supervised Learning
        • Fooled
        • Socratic Debate
        • Moral Machine
      • AI Coding Strategies
      • AI Computing Prompts
    • AI Prompts
  • Teaching & Learning
    • Wellbeing
    • Blog
    • Humour >
      • Teacher Humour
      • Teacher Humor
    • PLN Challenge >
      • Covering your backside
      • Online Privacy
      • Twitter Challenge >
        • Twitter All Star
        • Challenge 1
        • Challenge 2
        • Challenge 3
        • Tips for staying safe on Twitter
        • Tips for hosting Edu Twitter Chats
        • Tips for taking part in Twitter chats
        • It's all about the hashtag! Essential chats for educators
        • How to storify a chat
        • How to schedule Tweets
        • Twitter Lists
        • NT2tEU
      • Facebook Challenge >
        • Challenge 4
        • Challenge 5
        • Challenge 6
        • Tips for staying safe on Facebook
      • Google Challenge >
        • Challenge 7
        • Challenge 8
        • Challenge 9
      • Pinterest Challenge >
        • Challenge 10
        • Challenge 11
        • Challenge 12
        • Tips for using Pinterest
      • Blog Challenge >
        • Challenge 13
        • Challenge 14
        • Challenge 15
        • How to create a classroom blog
      • Staffrm Challenge >
        • Challenge 16
        • Challenge 17
        • Challenge 18
      • Skype Challenge >
        • Challenge 19
        • Challenge 20
        • Challenge 21
      • Edmodo Challenge >
        • Challenge 22
        • Challenge 23
        • Challenge 24
      • TeachMeet Challenge >
        • Challenge 25
        • Challenge 26
        • Challenge 27
      • In-school challenge >
        • Challenge 28
        • Challenge 29
        • Challenge 30
      • 30 ways to grow your PLN
    • Tools for Teachers >
      • Web 2.0 >
        • Top 10 Web 2.0 Tools
        • Classroom Response Tools
      • Quiz Tools
      • Classroom Management Tools
      • Software >
        • Media Conversion Tools
        • Application Software
      • Multimedia >
        • Free Music
    • BYOD
    • Digital Leaders >
      • Digital Leaders Blog >
        • DL Archive
      • DL Tips
      • Quotes
      • Links
    • Flipped Learning >
      • Flipped Classroom vs. Blended Classroom
    • Gamification >
      • Gamification vs. Game Based Learning vs. Game Design
    • School Closures
    • Game Based Learning >
      • Minecraft >
        • Minecraft in Education
        • Minecraft Lesson Ideas
        • Minecraft Literacy
        • Real Life Minecraft
        • Minecraft Top Tips
        • Minecraft Coding Tutorials >
          • Minecraft Code Builder Setup
          • Minecraft Code: Walking on Air
          • Minecraft Code: Hello World
          • Minecraft Code: Functions
          • Minecraft Code: Rainbow
          • Minecraft Code: Skyscraper
          • Minecraft Pixel Art
    • The magic of >
      • The magic of Computing
      • The magic of Maths
      • The magic of Science
      • The magic of Literacy
    • Road2e2
    • T&L Blog
  • Computing
    • Computing Blog >
      • GCSE Computer Science
      • General
    • Teaching Computer Science >
      • CPD >
        • Blocks to Code
        • Tutorials >
          • How to embed Flash into PowerPoint
          • How to embed YouTube videos in to PowerPoint
          • How to create a wiki
          • How to create a classroom blog
      • Schemes of Work
      • Programming Resources
      • Theory
      • Posters
      • Festive Computing Activities
      • FLOPPYS 2020
      • FLOPPYS 2021
      • FLOPPYS 2022
      • Game Design
      • App Creation
    • Theory Lessons >
      • Theory Tests
      • Computer Hardware >
        • Input / Output
        • CPU
        • LMC
        • Storage Devices
        • Memory (RAM / ROM)
        • Hardware
      • Binary Lessons >
        • Units of Data
        • Binary Representation
        • Binary Representation of Images
        • Binary Representation of Images (Festive)
        • Binary Representation of Characters
        • Binary Representation of Sound
        • Binary Representation of Instructions
        • Binary Addition
        • Hexadecimal
      • Software >
        • Operating System
        • Types of Software
        • Utility Software
      • Programming >
        • Flowcharts
      • Computational Thinking >
        • Data Science
    • Digital Literacy >
      • Social Media (Good or Bad thing?)
      • Cyberbullying
      • Staying Safe Online
    • ICT Strand >
      • Fake News Project >
        • Fake News 1
        • Fake News 2
        • Fake News 3
        • Fake News 4
        • Fake News 5
      • Spreadsheet Modelling
      • Superhero Movie Trailer
      • PowerPoint Task
      • Digital Imaging
      • Paint 3D Tutorial
    • Programming Lessons >
      • Scratch >
        • Festive Scratch >
          • Music Festive with Scratch
          • Turtle Snowflakes
          • What's your elf name
          • Secret Santa
        • Making music with Scratch
        • Sorting Hat Lesson
        • Turtle Time
        • Superhero name generator
        • Compliment Generator
        • Magic 8 ball
      • Python >
        • Chatbot
        • Coding Golf
        • Turtle Time >
          • Turtle Instructions
        • Magic 8 ball
        • Python Mad Libs
        • Rock Paper Scissors
        • Shakespearean Insult Generator >
          • Shakespearean Insult Generator Part 2
        • Compliment generator
        • Sorting Hat
        • Superhero name generator
        • Cards Against
        • Guess the word
        • Guess the number
        • Festive Python >
          • What's your elf name
          • Secret Santa
          • Turtle Snowflakes
      • Little Man Computer
      • Hour of Code >
        • Hour of Code Music
        • Python Tutorials
        • HoC 8-Bit Challenge
        • Music MicroPython (Festive)
      • Raspberry Pi >
        • Networking the Pi
        • Minecraft Pi
        • Harry Potter Sorting Hat >
          • Harry Potter Sorting Hat (GPIO)
        • Raspberry Pi LTSP (Networked Classroom)
        • Astro Pi
    • Homeschooling
    • Remote Learning >
      • Fun Python Tutorials
      • Python Tutorials >
        • Chatbot Tutorial
        • Dice Roll
        • Turtle Tutorial
        • Magic 8 ball
        • Sorting Hat
        • Rock Paper Scissors Tutorial
        • Cards Against
        • Python Mad Libs
        • Shakespearean Insult Generator >
          • Shakespearean Insult Generator Part 2
        • Guess the word
        • Guess the number
        • Superhero name generator
        • Compliment generator
        • Festive Python Tutorials >
          • What's your elf name
          • Secret Santa
          • Turtle Snowflakes
      • Scratch Tutorials >
        • Sorting Hat
        • What's your superhero name
        • Turtle Time Tutorial
        • Compliment Generator
        • Magic 8 Ball
        • Festive Scratch Tutorials >
          • Festive Music with Scratch
          • Secret Santa Scratch Tutorial
          • Turtle Snowflakes Tutorial
          • What's your elf name
    • Revision >
      • Data Representation >
        • Binary Representation of Images
        • Binary Representation of Sound
  • 21 Things
    • 21 Things To Try >
      • ConnectEd
      • Social Media >
        • Twitter
        • Pinterest
        • Facebook Groups
        • Facebook Pages
        • Google+ Communities
        • Staffrm
        • Edmodo
        • Mystery Skype
        • Blogging
        • Classroom Blogging
      • Gamification
      • Flipped Classroom
      • Breakout Edu
      • Edu Podcasts
      • Jar of Awesome
      • TeachMeet
      • Team Teaching
      • Mixed Reality
      • Digital Leaders
      • Genius Hour
      • Sketchnoting
    • Computing >
      • CS 20
      • Code Golf
      • PRIMM
      • Under The Hood
      • Unplugged
      • Podcasts
      • Facebook Groups CS
      • Flipped Classroom CS
      • Teach with Magic
      • Socratic Debate
      • Coding Music
    • 21 Things Keep Fit >
      • 20 Health Hacks
      • Home Health Hacks
    • 21 Things PLN >
      • Edmodo
      • Twitter
      • Reply to a blog
      • Skype
      • Cofee Edu
      • Pinterest
      • Reach out
      • Conferences
      • Instagram
      • Ning
      • MEC
      • Voxer
      • LinkedIn
  • Microbit
    • Physical Computing >
      • micro:bit LEDs
      • micro:bit PIR
      • micro:bit Servo
      • micro:bit Temp
      • micro:bit LDR
      • micro:bit Moisture
      • micro:bit RGB LEDs
      • micro:bit HC-SR04 3v3
      • micro:bit HC-SR04 5v
      • micro:bit Push button
      • micro:bit Potentiometer
      • micro:bit Piezo
    • Music >
      • Music Festive
    • Festive Projects
    • Projects >
      • Music
      • Music MicroPython
      • Servo Animals
    • Lessons >
      • Magic 8 Ball
      • Harry Potter Sorting Hat
    • Quick Start Guide
    • Microbit Simulator
  • #100 Ideas
    • Testimonials
    • Competition >
      • Competition 2
    • Worksheets
    • Bonus Ideas >
      • What's your elf name
      • Make me happy
      • Guess the word
      • Cards Against Humanities
      • Compliment generator
      • Data Science
    • Curriculum
    • ISTE
    • CSTA
  • About
    • Privacy
Search by typing & pressing enter

YOUR CART

Creating a chatting robot (Chat bot)

​Learn how to create a basic chat bot using this free python web tutorial.

Like this tutorial? Share it with your followers by clicking on the image below.

Picture
This tutorial is based on the work of Carrie Anne Philbin for the Raspberry Pi Foundation and is licenced under the Creative Commons Attribution 4.0 International License. (See credits below)

 
Introduction:

Can computers think? This was a question posed by computer pioneer and artificial intelligence (AI) theorist, Alan Turing. Turing proposed that, given time, a computer with sufficient computational power would acquire the abilities to rival human intelligence. In order to test his theory, Turing devised a test. 

The Turing Test was based on a Victorian parlour game in which a judge (or interrogator) asks a series of questions to a man and a woman in a separate room. By reading a series of typed answers, the judge must determine which replies were from the man and which were from the woman.

Turing adapted the test by replacing the woman with a computer - the aim being to decide whether the answers were from a man or computer thus determining if a computer was able to think for itself.

To find out more about Alan Turing and the Turing Test, click on the links below:

  • http://www.turing.org.uk - Online biography about Alan Turing
  • http://en.wikipedia.org/wiki/Alan_Turing - Alan Turing wikipedia page
  • http://www.bbc.co.uk/history/people/alan_turing - BBC History: Alan Turing
  • http://en.wikipedia.org/wiki/Turing_test - The Turing Test wikipedia page
  • http://www.turing.org.uk/scrapbook/test.html - Alan Turing Scrapbook: The Turing Test

Chat bots

For years, science fiction writers and filmmakers have dreamed about robots that can think for themselves however, despite giant leaps in technology, this dream is still far from reality. To explore the reasons why it is so difficult to make a thinking robot, we are going to create our own chatting robot (chat bot) in Python. 

Use the window (above) to test your code.
STEP 1 - Creating a chat bot
​
In order for the chat bot to work, you will need to import the time and random libraries.
​import time
import random
​Next, we need to ask the user a question and store the response in a variable. Add the following:
name = input("Hello, what is your name? ")
​Next, we want to give the user the impression that they are chatting to a real person, therefore, we need to place a pause in-between each new question / response. To do this, we will use the time `time.sleep()`. Enter the following:
​time.sleep(2)
​Next, we need to create a response from the computer. We want the reply to sound personalised so we are going to add the users name to the end of the response. To do this, we will use the concatenation `+` command. Add the following code to their script:
print("Hello " + name)
Next we are going to ask the user how they are feeling. We will store this in a variable called 'feeling'. Add the following:
feeling = input("How are you today? ")
​​​time.sleep(2)
Next, we are need to create a response. In order for the computer to appear human, we need to have a set of different responses. To do this, we will use an `if` statement. We will start with the response for 'if' the user is feeling "good". Add the following:
​if "good" in feeling:
    print("I'm feeling good too!")
else:
    print("I'm sorry to hear that!")
So far, there is very little variation in our answers. In order to make our chat bot appear more human, we are going to add a list of random possible answers.
​First, add an input() asking the user to enter their favourite colour (remembering to add a natural pause):
​time.sleep(2)
favcolour = input("What is your favourite colour? ")
Next, create a list of possible responses:
colours = ["Red","Green","Blue"]
Finally, add a response by choosing a colour from the list at random:
time.sleep(2)
print("My favourite colour is " + random.choice(colours))
Your finished code should look like this:
STEP 2 - Improving your chat bot

  • There is a problem with the code. The code in Python is case sensitive therefore, if we were to type in "Good" (Uppercase G) instead of "good" in response to the question "How are you feeling?" Python will not find a match and will therefore reply with "I'm sorry to hear that!". In order to get around this problem, we can convert the users reply to lower case using the `lower()` command.
  • Modify your code as follows:
if "good" in feeling.lower():
    print("I'm feeling good too!")
  • At the moment, we only have two responses to the question "How are you feeling?" Add some more responses to make the chat bot appear more realistic. For example:
feeling = input("How are you today? ")
if "good" in feeling:
    print("I'm feeling good too!")
elif "awesome" in feeling:
    print("I'm feeling awesome too!")
else:
    print("I'm sorry to hear that!")
STEP 3
  • Add some more questions and responses
  • Comment their code explaining how it works.
  • Add a random pause between each question and answer:
​time.sleep(random.randrange(5))

Resources:
Example solution
chat_bot.zip
File Size: 0 kb
File Type: zip
Download File


You may also like:

Picture

You may also be interested in:
  • Python Shakespearean insult generator
  • Python Mad Libs
  • Code Golf
  • Python Sorting Hat
  • Python Magic 8-Ball 
  • Cards Against Humanities​
  • Guess the word
  • Guess the number

​Licence:

Unless otherwise specified, everything in this repository is covered by the following licence:
Picture
Python Turing Test is licenced under a Creative Commons Attribution 4.0 International License.

Based on a work at https://github.com/raspberrypilearning/turing-test-lessons
Powered by Create your own unique website with customizable templates.