Question: Complete the function listmodn that, given an input list alist, an input value n, and an input index i, will attempt perform the modulo n

Complete the function listmodn that, given an input list alist, an input value n, and an input index i, will attempt perform the modulo n operation on the i-th element of alist and return this value. Using try/except/else, the function should handle ZeroDivisionError and IndexError exceptions.


If a ZeroDivisionError occurs, the function should return: float('Inf').

If an IndexError occurs, the function should return: float('Nan').

If no error occurs, the function will return the i-th element of alist taken modulo n.

For example:


a=[10,20,30,40,50,60,70,80,90]

print(listmodn(a,5,11))


would return a value of 5, but


a=[10,20,30,40,50,60,70,80,90]

print(listmodn(a,20,3))


would return a value of Inf.

Step by Step Solution

3.47 Rating (160 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

1 def listmodnalistin 2 try return alistin here i i... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!