BaşlayınÜcretsiz Başlayın

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.

Bu egzersiz

Building Chatbots in Python

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • 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'.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# Define replace_pronouns()
def replace_pronouns(message):

    message = message.lower()
    if 'me' in message:
        # Replace 'me' with 'you'
        return ____
    if 'my' in message:
        # Replace 'my' with 'your'
        return ____
    if 'your' in message:
        # Replace 'your' with 'my'
        return ____
    if 'you' in message:
        # Replace 'you' with 'me'
        return ____

    return message

print(replace_pronouns("my last birthday"))
print(replace_pronouns("when you went to Florida"))
print(replace_pronouns("I had my own castle"))
Kodu Düzenle ve Çalıştır