write a python function Check_Exception(index, *list)(Refer RollNo_W10A_1.py) which accepts an index value to access the list element and a list composed of numbers. Your function should produce the required element while taking care of the following cases via exception handling as shown in the example.
When the given index value is out of range on the input list.
When the index value is not an integer.
When no value is provided.
def Check_Exception(index, *list):
if index >= 0 and index < len(list):
if index % 1 == 0:
if list[index]:
return list[index]
else:
return 'Value is provided'
else:
return 'Index value is not an integer'
else:
return 'Index value is out of range on the input list'
print(Check_Exception(2, 5, 3, '', 6, 4)) # Value is provided
print(Check_Exception(2, 5, 3, 10, 6, 4)) # 10
print(Check_Exception(2.5, 5, 3, 2, 6, 4)) # Index value is not an integer
Comments
Leave a comment