This module focuses on exception handling in Python, including the use of try
and except
, custom exceptions,
and managing errors effectively in code.
- Solution
- Description:
Task "Programmers Can Do Everything":
- Implement a function
add_everything_up
that can add integers, floats, and strings together. If a number is added to a string, it should return the string representation of both instead of raising a TypeError.
- Implement a function
- Solution
- Description:
Task "Count and Average":
- Create two functions:
personal_sum
to calculate the sum of numeric values in a collection, handling TypeErrors for non-numeric values.calculate_average
to compute the average usingpersonal_sum
, handling ZeroDivisionError and TypeError for invalid data types.
- Create two functions:
- Solution
- Description:
Task "Inaccuracy":
- Implement a
Car
class with methods for validating VIN and number attributes. Create two custom exception classes,IncorrectVinNumber
andIncorrectCarNumbers
, to handle validation errors when creating instances ofCar
.
- Implement a