1. Learn
  2. /
  3. Courses
  4. /
  5. Building Chatbots in Python

Exercise

ELIZA III: Pronouns

To make responses grammatically coherent, you'll want to transform the extracted phrases from first to second person and vice versa. In English, conjugating verbs is easy, and simply swapping "me" and 'you', "my" and "your" works in most cases.

In this exercise, you'll define a function called replace_pronouns() which uses re.sub() to map "me" and "my" to "you" and "your" (and vice versa) in a string.

Instructions

100 XP
  • If 'me' is in message, use re.sub() to replace it with 'you'.
  • If 'my' is in message, replace it with 'your'.
  • If 'your' is in message, replace it with 'my'.
  • If 'you' is in message, replace it with 'me'.