The code uses place holders with numbered indexes and String “format” Method to specify the…

The code uses place holders with numbered indexes and String
“format” Method to specify the format of the response and then
create the response. Make sure you understand these ideas by going
through the code. Focus on how the response pattern is specified in
list “eliza_engine” and formatted response is generated using
“format” method inside the “regex_replace” function. • The
parameters to “format” method uses the idea of unpacking operator
(*) in Python applied to collection data types such as lists and
tuples. Make sure you understand this idea as well. 3. At current
situation, the “regex_replace” function returns combination of “You
Said: ” and the input, as the response for inputs shown in the
following table.


Add a rule to the list “eliza_engine” so that the corresponding
output given in the table will be returned for such string

Input Output
Well, my boyfriend made me come here. WHY DID YOUR BOYFRIEND MADE YOU COME HERE?
Well, my friend made me run fast. WHY DID YOUR FRIEND MADE YOU RUN FAST?
Well, my parents made me go there. WHY DID YOUR PARENTS MADE YOU GO there?
Well, my boyfriend made him go away You Said: WELL, MY BOYFRIEND MADE HIM GO AWAY.
my friend made me run fast. You Said: MY FRIEND MADE ME RUN FAST.

2) you should be comfortable with searching using regular
expression in Python and the ideas of using “” method,
accessing capture groups in search results, using format function
and place holders to format strings, using unpack operator in
Python and writing regular expressions with capture groups.

import re

def simple_eliza_demo(user_input):
uip = user_input.upper()
eliza_engine = [ [“^.* I’M (DEPRESSED|SAD) .*”, “I AM SORRY TO HEAR
YOU ARE {0}”, “true” ] ,
“true” ],
[“^.* ALL .*”, “IN WHAT WAY?”, “false”] ]
for rule in eliza_engine:
response = regex_replace(uip, rule[0], rule[1], rule[2])
return response
return “You Said: ” + uip

def regex_replace(text, pattern, response, add_match):
result =, text);
if(add_match == ‘true’):
return response.format(*result.groups());
return response;
inputs = [ “Hello! I’M depressed and tired.”,
“Hello! I AM depressed and tired.”,
“Hello! I’M sad and tired.”,
“Hello! I AM tired and sad.”,
“Hello! I’M tired and sleepy.”,
“Men are all alike.”,
“They aere always bugging us about something or other.”,
“Well, my boyfriend made me come here.”,
“He says I’m depressed much of the time.” ]

for inp in inputs:
print(“Input: ” + inp)
print(“Response: ” + simple_eliza_demo(inp))

Place your order
(550 words)

Approximate price: $22

Calculate the price of your order

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
The price is based on these factors:
Academic level
Number of pages
Basic features
  • Free title page and bibliography
  • Unlimited revisions
  • Plagiarism-free guarantee
  • Money-back guarantee
  • 24/7 support
On-demand options
  • Writer’s samples
  • Part-by-part delivery
  • Overnight delivery
  • Copies of used sources
  • Expert Proofreading
Paper format
  • 275 words per page
  • 12 pt Arial/Times New Roman
  • Double line spacing
  • Any citation style (APA, MLA, Chicago/Turabian, Harvard)

Our guarantees

Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.

Money-back guarantee

You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.

Read more

Zero-plagiarism guarantee

Each paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.

Read more

Free-revision policy

Thanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.

Read more

Privacy policy

Your email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.

Read more

Fair-cooperation guarantee

By sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.

Read more
error: Content is protected !!