Exceptions Handling in Python Challenges
# Question
1. Write a Python program that creates a new list containing the square root of the following
list items l1 = [36, -25, -49]. Make sure to catche error if any exists
Expected output:
no sqrt for negative numbers
2. Assume we have the following generator: lst = [1, 2, 3,4,5], gen = (x*x for x in lst)
Print the generators items using 'while' loop and 'next()' function without letting the code
throw an exception
Expected output:
16
25
Kuala Lumpur, Malaysia, phone: +601160906599, e-mail:academysamer@[Link]
# Question
3. Write a Python program that tries to print values of some dictionary keys which are not
available and catch that error.
Where our dictionary is:
student_dict = {"name": "Huda", "age": 24, " course": "Python Beginner to Advanced"}
Try to print student_dict['year']
Expected output:
Sending the error to the system logger
The following exception ('year') has been raised
To find out more about Python, web development, and data science visit us on:
Kuala Lumpur, Malaysia, phone: +601160906599, e-mail:academysamer@[Link]