Section 1: Generating Sentences

We have generated language in several ways in this class already.

One way was with the simple language generator. We typed in a model (a sentence pattern) and a dictionary of words by parts.

../_images/SentenceGenerator.png

We have also done sentence generation in Snap. We have a language generation project that lets us generate sentences by parts, just like in the simple language generator.

../_images/picking-words-from-variables.png

The Python Version V1

The below program does the same thing in Python. Click ‘Run’ to generate a random sentence.

Try answering these questions about the code above.

The Python Version V2

The below program does the same thing in Python. Click ‘Run’ to generate a random sentence.

Try answering these questions about the code above.

Section 2: Creating a little Python chatbot

You have built Chatbots in both Snap! and Charla-bots. Here’s an example on a little one:

../_images/Snap-kinda-chatbot.png

Here is a (very) little Python chatbot. This one is a little more sophisticated than our Snap chatbot – it can pick out a name from an input sentence, and it can do the equivalent of respond randomly that we saw in Charla-bot.

Python here in a Runestone ebook can’t receive user input, so let’s just change the inputSentence variable to represent what the user says. Press Run to see what the chat bot says.

This code is recognizing words in the inputSentence then deciding what to print in response.

You have attempted of activities on this page