0% found this document useful (0 votes)
4 views2 pages

Python Exception Handling Challenges

The document presents three Python programming challenges focused on exception handling. The first challenge involves calculating the square root of a list while managing errors for negative numbers. The second challenge requires printing items from a generator using a while loop and the next() function, and the third challenge involves accessing a non-existent key in a dictionary and logging the error.

Uploaded by

ami
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Python Exception Handling Challenges

The document presents three Python programming challenges focused on exception handling. The first challenge involves calculating the square root of a list while managing errors for negative numbers. The second challenge requires printing items from a generator using a while loop and the next() function, and the third challenge involves accessing a non-existent key in a dictionary and logging the error.

Uploaded by

ami
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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]

You might also like