Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

*Python 3 Question* In the 1960s, computer scientist Joseph Weizenbaum wrote a computer program named ELIZA that parodied a conversation with a psychotherapist. ELIZA responded,

*Python 3 Question*

In the 1960s, computer scientist Joseph Weizenbaum wrote a computer program named ELIZA that parodied a conversation with a psychotherapist. ELIZA responded, using scripted replies, to simple sentences typed in by the user. For this program, we will implement a very basic Python version of the ELIZA program.

1. Start by defining a function named longestWord(). This function takes a string as its argument, representing a sentence with one or more words. The function returns the longest single word in the input (if multiple words share the same greatest length, then the first one to occur in the sentence is returned). You may assume that the input does not contain any punctuation, and that the words in the input are all separated by spaces (

Hint: use the split() function here).

Once you have your list of individual words, use a loop to find the longest word. Here is some helpful pseudocode:

Set longest to 0 (the index of the longest word seen so far)

Set i to 1

While i is less than the length of the list:

If the length of list[i] is greater than the length of list[longest]:

Set longest to i

Add 1 to the value of i

At the end of the loop, longest will hold the index of the longest word in the list.

2. Next, define a function named nextResponse(). This function takes a single argument, representing a single word. The function returns a new string based on the length of the input word. This string represents the next question to be asked by the program. Suppose that the input word is X. If the word is exactly 4 characters long, return the string (with an appropriate substitution for X) "Tell me more about X." If the word is exactly 5 characters long, the response should be, "Why do you think X is important?" If the word is 6 or more characters long, the response should be "Now we are getting somewhere. How does X affect you the most?" If the word's length is 3 or less, the response should be "Maybe we should move on. Is there something else you would like to talk about?"

3. Finally, at the bottom of your source code file, write the main logic for your program, which will call the functions you defined in the previous steps. Your program should start by asking the user "What would you like to talk about?" Until the user types "Goodbye" (with that exact capitalization), your program should enter a loop where it processes the user input, prints an appropriate response, and then reads in a new response from the user. If the user response contains the lowercase word "you" (or any word that includes the lowercase character sequence "you"), the program should print out

I'm not important. Let's talk about you instead. as its next prompt. Otherwise, find the longest word in the user's response and call nextResponse()

to get the next input prompt. Once the user types "Goodbye", your program should print a farewell message and end.

A pseudocode algorithm would look something like the following:

prompt "What would you like to talk about?"

answer user input via input() and the prompt variable

while answer does not equal "Goodbye":

if answer contains "you":

prompt "I'm not important. Let's talk about you instead."

else:

word longest word in answer

prompt next response based on longest word

Read in a new value for answer via input() and the prompt variable

Save and test your code. Test it out with a brief conversation to make sure that it seems to be working properly, and fix any bugs that you may find. Note that this is an extremely simplistic implementation of ELIZA, and so its responses will often border on the strange, if not outright bizarre.

image text in transcribed

Sample Program Execution (program output is in italics, and user input is bold) What would you like to talk about? i like cse 101 Tell me more about like like means to enjoy something Now we are getting somewhere. How does something affect you the most? what do you mean I'm not important. Let's talk about you instead. what is it Tell me more about what Goodbye Thank you for chatting with me. Sample Program Execution (program output is in italics, and user input is bold) What would you like to talk about? i like cse 101 Tell me more about like like means to enjoy something Now we are getting somewhere. How does something affect you the most? what do you mean I'm not important. Let's talk about you instead. what is it Tell me more about what Goodbye Thank you for chatting with me

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

7th edition

978-1111825911, 1111825912, 978-1133684374, 1133684378, 978-111182591

More Books

Students also viewed these Databases questions

Question

6. Explain how to train managers to coach employees.

Answered: 1 week ago