"""
there is no need of semicolon. We will show error for something else
"""
print "Hello Python..."
a = 10
b = 5
c = 5
x = a/(b-c) #It will show ZeroDivisionError
print "x = ", x
y = a/(b+c)
print "y = ", y
a = 10
b = 5
c = 5
try:
x = a/(b-c)
except Exception,e :
print "Division by zero"
y = a/(b+c)
print "y = ",y
import sys
invalid = 0
count = 0
for i in sys.argv:
try:
a = int(i)
except:
invalid += 1
print "Invalid number" , i
continue
count += 1
print "Valid Numbers : " ,count
print "Invalid numbers ",invalid
a = [5,10]
b = 5
try:
x = a[2]/b - a[1]
except AssertionError:
print "AssertionError:"
except IndexError:
print "Array Index Error"
except Exception:
print "Any Error"
y = a[1]/a[0]
print "y = " , y
x = 5
y = 1000
class MyException(Exception):
def __init__(self, message):
Exception.__init__(self, message)
def error(self):
print self.message
try:
z = x/y
if(z<0.01):
raise MyException("Number is too small")
except MyException, error:
print "Caught MyException"
print error.message
finally:
print "I am always here"