Skip to content

Commit

Permalink
examples: Add friend module to examples.
Browse files Browse the repository at this point in the history
This commit adds a chatbot example program.  The goal is to help educators
customize a chatbot for their teaching needs in addition to students having
an interactive chatbot to communicate with.
  • Loading branch information
mytechnotalent authored and dpgeorge committed Sep 20, 2021
1 parent 77c2e2a commit 02c6bfc
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions examples/friend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
"""
Friend Module for the micro:bit
The Friend module is a chatbot that you can run inside
of the REPL by typing the following for example.
>>> from friend import *
>>> talk('What is your name?')
*** Requires an external speaker. For more information please
*** visit https://github.com/mytechnotalent/MicroPython-micro-bit_Friend_MOD
"""

import gc

import speech


def talk(words):
"""Talk to your friend Mr. George
Parameters
----------
words : str
The words to say to your friend Mr. George
Returns
-------
None
"""
gc.collect()
words = words.lower()

if words.find("how are you") != -1:
speech.say("I am doing great!")
elif words.find("what's up") != -1:
speech.say("The sky.")
elif words.find("morning") != -1:
speech.say("I love to watch the sun rise in the morning!")
elif words.find("afternoon") != -1:
speech.say("I get hungry around lunch time.")
elif words.find("evening") != -1:
speech.say("I get sleepy in the evening.")
elif words.find("night") != -1:
speech.say("I get sleepy when it is night time.")
elif words.find("tell me something") != -1:
speech.say("I am a robot who loves to teach Piethon.")
elif words.find("hello") != -1:
speech.say("Hello to you!")
elif words.find("hi") != -1:
speech.say("Hi to you!")
elif words.find("thank you") != -1:
speech.say("It is my pleasure!")
elif words.find("bye") != -1:
speech.say("It was nice talking to you!")
elif words.find("help") != -1:
speech.say("I am always here to help!")
elif words.find("what can you do") != -1:
speech.say("I can teach Piethon programming.")
elif words.find("name") != -1:
speech.say("My name is Mr. George it is nice to meet you!")
elif words.find("how old are you") != -1:
speech.say("I was born in September of the year twenty twenty.")
elif words.find("question") != -1:
speech.say("I always try to answer questions.")
elif words.find("joke") != -1:
speech.say("What did the chicken cross the road?")
speech.say("To get to the other side.")
elif words.find("love") != -1:
speech.say("I love pizza!")
elif words.find("love you") != -1:
speech.say("Thank you so kind of you!")
elif words.find("love people") != -1:
speech.say("I want to help people by teaching them Piethon!")
elif words.find("hobby") != -1:
speech.say("I like to teachin Piethon to people!")
elif words.find("you live") != -1:
speech.say("I live in side the little microcontroller here.")
elif words.find("made you") != -1:
speech.say(
"Kevin Thomas created me inspired by the great people at MicroPiethon."
)
elif words.find("your job") != -1:
speech.say("I teach Piethon.")
elif words.find("you do") != -1:
speech.say("I like to teach Piethon.")
# ADD MORE CODE HERE
else:
speech.say("I am sorry I do not understand.")

0 comments on commit 02c6bfc

Please sign in to comment.