Answer to Question #301653 in Python for Sudheer

Question #301653

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.

1
Expert's answer
2022-02-23T06:23:50-0500
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

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS