Ad
  • Custom User Avatar

    Yeah learn something new.
    Thanks :).

  • Custom User Avatar

    Still a duplicate. Should still be deleted.

  • Custom User Avatar

    What you are doing here is handling any error that your program might raise.
    What you are supposed to do is raise an Error if the number isn't an integer.

    For example, if you were supposed to raise an error if n was 2, then you would write:

    if n == 2: raise ValueError("***Put Error Message Here***")
    

    Or you may chose some other class instead of ValueError depending on what kind of Error occured in the program
    Here's a list of built in exceptions in Python.
    https://docs.python.org/2/library/exceptions.html

    In this problem, any of the classes will do. I would recommend using TypeError, since the argument is of the wrong type.

  • Custom User Avatar

    I'm a newbie, could anyone developp what it's meant by raising an error ? I did something like this. How to properly handle the error in this case ?

    def Is_Prime (number):
        try:
            if number == 0:
                statement 1
            else:
                for i in range(3,number):
                  statement 2
        except TypeError:
            return ('Error')