Checking words

Report a typo

Analyze the following code. Match each input with its result.

class WordError(Exception):
    def __init__(self, w):
        self.message = "Your word is '%s!' Try again!" % w
        super().__init__(self.message)


word = input("Enter your word here: ")

try:
    if word == "pig":
        raise WordError(word)
    elif word == "cup":
        raise WordError(word)
    else:
        print(word)
except WordError as err:
    print(err)
Match the items from left and right columns
sky
pig
cup
green
sky
Your word is 'pig!' Try again!
green
Your word is 'cup' Try again!
___

Create a free account to access the full topic