The __init__ method

Report a typo

We have created the exception class called NotWordError:

class NotWordError(Exception):
    def __init__(self, word):
        self.message = word + " is not a word, sorry!"
        super().__init__(self.message)

It takes the wrong word and prints an error message about it. The class is already defined in the code, so you can use it.

First, create a function check_word(word) that checks if the given word contains a zero ('0'). If not, the function should return the given word. If it does, the NotWordError should be raised.

Then, create a new function error_handling(word). It should call the check_word() function and use the try-except block to catch the NotWordError. If the error occurs, print its error message. If not, print the result of the check_word() function.

Write a program in Python 3
def check_word(word):
...

def error_handling(word):
...
___

Create a free account to access the full topic