Write a python function that accepts a list of numbers and try to find out the value of a ‘magic index’. The ‘magic index’ is calculated as the ratio of the largest and smallest list element. The python function Magic_Index(A) (Refer RollNo_W10B_1.py)Take a list of elements and return the value of the magic index or error message for any possible exceptions. The error message will be "error occurred = error name".
def magic_index(arr):
try:
return max(arr)/min(arr)
except ZeroDivisionError:
return 'error occurred = ZeroDivisionError'
except TypeError:
return 'error occurred = TypeError'
except ValueError:
return 'error occurred = ValueError'
arr = [2, 3, 5.5]
print(magic_index(arr))
Comments
Leave a comment