The assert
statement exists in almost every programming language. When you do:
assert condition
or:
assert condition, message
It's equivalent to this:
if __debug__:
if not condition: raise AssertionError(message)
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.
Error raised when the user presses the interrupt key, normally Ctrl + C or del.
You tried to calculate 1/0
which is undefined. See this example to find the divisors of a number:
div = float(raw_input("Divisors of: "))
for x in xrange(div+1): #includes the number itself and zero
if div/x == div//x:
print x, "is a divisor of", div
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 = float(raw_input("Divisors of: "))
for x in xrange(1,div+1): #includes the number itself but not zero
if div/x == div//x:
print x, "is a divisor of", div
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)