Example HTML page

P-Assignment 18: Exceptions

Hi,

Please do the following programs.

  1. Write a python program to access the array element whose index is out of bound and handle the corresponding exception.(Hint: Consider a list having 3 elements  (ex: 1,2,3 )but you have to access the fourth element which is not there in that list. So that it raises an exception and  it is to be handled.)
  2. Write a python script to Raise an instance of the Exception class itself.
  3. Write a function to compute 5.7/0 and use try/except to catch the exceptions.
  4. Write a python script to verify that every number in the list [2,4,6,8] is even by using assert statement.
  5. Write a python script to verify that every number in the list [1,3,5,7] is odd by using assert statement.
  6. Try to write a python script to handle multiple errors with one except statement.(Hint: Initialize two or more errors under try section. You may also use if condition if needed. Use except(first error name,second error name)for handling the errors that occurred.)
  7. Write a python script to work within specific parameters.(Hint: if you want to limit the user-input to only positive integers, raise an exception. If the user input is 3 it prints 3 as output, if the user gives -3 as input then the output must be “please give a positive number”. You may use while statement if required.)
  8. Write a python script to raise an exception when you try to access the key value which do not exist in dictionary.(Hint: Create a dictionary and insert some keys and values in it. Then access an element which is not in that dictionary.)
Example HTML page

Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest