Handle the exception thrown by the code below by using try and except blocks.
for i in ['a','b','c']:
print i**2
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-1-908335551eea> in <module>() 1 for i in ['a','b','c']: ----> 2 print i**2 TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'
Handle the exception thrown by the code below by using try and except blocks. Then use a finally block to print 'All Done.'
x = 5
y = 0
z = x/y
--------------------------------------------------------------------------- ZeroDivisionError Traceback (most recent call last) <ipython-input-2-3effb78be709> in <module>() 2 y = 0 3 ----> 4 z = x/y ZeroDivisionError: integer division or modulo by zero
Write a function that asks for an integer and prints the square of it. Use a while loop with a try,except, else block to account for incorrect inputs.
def ask():
pass()
ask()
Input an integer: null An error occurred! Please try again! Input an integer: 2 Thank you, you number squared is: 4