Other Errors

suggest change

AssertionError

The assert statement exists in almost every programming language. When you do:

assert condition

or:

assert condition, message

With a message, it’s equivalent to this:

if __debug__:
    if not condition: raise AssertionError(message)

assert condition with no message raises AssertionError with no argument. Assertions can include an optional message, and you can disable them when you’re done debugging.

Note: the built-in variable __debug__ is True under normal circumstances, False when optimization is requested (command line option -O). Assignments to __debug__ are illegal. The value for the built-in variable is determined when the interpreter starts.

KeyboardInterrupt

Error raised when the user presses the interrupt key, normally Ctrl+C or Delete.

ZeroDivisionError

You tried to calculate 1/0 which is undefined. See this example to find the divisors of a number:

div = int(input("Divisors of: "))
for x in range(div+1): #includes the number itself and zero
    if div/x == div//x:
        print(x, "is a divisor of", div)

It raises ZeroDivisionError because the for loop assigns that value to x. Instead it should be:

div = int(input("Divisors of: "))
for x in range(1,div+1): #includes the number itself but not zero
    if div/x == div//x:
        print(x, "is a divisor of", div)

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents