In [1]:
for i in ['a','b','c']:
try:
result = i**2
except TypeError:
print("Type error attempting to run on {i}".format(i=i))
else:
print result
In [3]:
x = 5
y = 0
try:
z = x/y
except ZeroDivisionError:
print("Cannot divide by zero")
finally:
print 'all done'
In [4]:
def ask():
while True:
try:
input = int(raw_input("Enter an integer: "))
except:
print 'Could not make conversion. Try again'
else:
print input**2
In [ ]:
ask()