How can I find the average of a list in Python and handle cases where the list is empty or contains non-numeric values?

I have a list of numeric values, and I want to find the average of all the elements in the list. I am currently using the sum() function to get the sum of all elements and then dividing by the length of the list. However, I am not sure how to handle cases where the list is empty or contains non-numeric values like strings.

Here is an example of my current code:


my_list = [1, 2, 3, 4, 5]
average = sum(my_list) / len(my_list)
print(average)

This works fine for lists with numeric values, but I am not sure what to do if the list is empty or contains non-numeric values.

Can someone please provide me with some guidance on how to handle these cases?