Pencil code program: Lady MacBeth Chat Bot
About this lesson
Use this program to create an interactive chat bot who answers questions as if she is Lady Macbeth. Have students analyze, fill in or change parts of, or use the program to create their own variation and rendition of a character. This program could be used to further your understanding of how you could use Pencil Code in the classroom, as a demonstration or discussion with your students, or as a way to introduce various CT concepts.
Year band: 7-8, 9-10Curriculum Links
Links with Digital Technologies Curriculum Area
|7-8||Processes and Production Skills||
Implement and modify programs with user interfaces involving branching, iteration and functions in a general-purpose programming language (ACTDIP030)
|9-10||Processes and Production Skills||
Implement modular programs, applying selected algorithms and data structures including using an object-oriented programming language (ACTDIP041)
Links with English Curriculum Area
|9-10||Literature / Literature and context||
Interpret and compare how representations of people and culture in literary texts are drawn from different historical, social and cultural contexts (ACELT1633)
Provide the quote:
‘Thy bones are marrowless, thy blood is cold
Thou hast no speculation in those eyes’
Have students guess which literature character said those words. (Lady Macbeth)
Lady Macbeth is a character from Shakespeare that students may be familiar with through studies of English literature.
In programming we can use this context to create a chatbot that responds to a user’s text input in a style that would reflect the Lady Macbeth character. To acheive this, we will be using the pencil code program new.pencilcode.net
Ask students to recall particular scenes or quotes from the famous Shakespeare play. To refresh students’ memory use this study guide Lady Macbeth.
Provide students with the chatbot pencil code program. Copy/Paste the program into a ‘Blank Editor’ on the Pencil Code website (new.pencilcode.net).
Explore how the chatbot responds to particular text inputs.
Can you work out what words the chatbot will respond to?
Have students analyze or fill in or change parts of the pencil code program.
Ways to remix the program
- Change or add to the chatbot responses for each user input.
- Add new keywords and chatbot responses.
- Change the introductory text to invite the user to enter text.
- Create their own code in python to respond as Lady Macbeth.
Learning reflection: Refining an algorithm based on new constraints (10 minutes)
How well did the pencil program work?
What changes or modifications did you make?
How well did these changes work?
Computational Thinking Concepts
|Abstraction||Identifying and extracting relevant information to define main idea(s)|
|Pattern Recognition||Observing patterns, trends, and regularities in data|
* Explore the Computational Thinking Concepts Guide for a list of the CT concepts noted on ECT, including tips for implementing each concept in your classroom.
Pencil code program
Copy/Paste the following program into a ‘Blank Editor’ on the Pencil Code website (new.pencilcode.net)
# Copyright 2015 Google Inc. All Rights Reserved. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # http://www.apache.org/licenses/LICENSE-2.0 # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. replyto = (words) -> for word in words switch word when "hello" return "Hello. I'm waiting." # For example, if asked "Who are you?" when "name", "who" return "Lady Macbeth." # E.g.: "Have you heard about the murder?" when "power", "kill", "duncan", "murder", "king" return """ I love power. I will do anything for power. """ when "prophecy" , "prophesy" , "prophesies" return """ I think the prophesies are true, but I think that we have to make them come true. We can't just rely on fate. We have to take matters into our own hands. """ when "witches", "fair", "foul" return """ They say that Fair is foul, and foul is fair, and I agree. """ when "blood", "hand" return """ All we have to do is wash our hands of it. """ when "plan", "idea", "plans", "plot" return """ All we have to do is wash our hands of it." """ return random [ "Are you a man?" "Was hope drunk wherein you dressed yourself?" "Only look up clear. To alter favor ever is to fear. Leave all the rest to me." ] while true await readstr "Ask me anything.", defer t words = t.toLowerCase().split /[\s\.,!?]+/ write replyto words