Error Handling

  1. Error Handling

    Question 1 of 3

    • Write a function that takes a string and returns number of lowercase characters in it. Ensure TypeError is handled.
    • Write a function that takes mass in kg and volume in cubic meter and returns density. Ensure ZeroDivisionError and TypeError is handled.
    • Write a function get_name that accepts a dictionary and returns the value of key name. Ensure KeyError is handled.
    • Write a function get_third_element that accepts a list and returns the third element. Ensure IndexError is handled.
  2. Raising Error

    Question 2 of 3

    • Write a function can_drink that takes age and checks if user can drink. If user is 18+, return True else return False. Note: You need to raise TypeError if age is not integer value, ValueError if age is below 0, AssertionError if age is above 100.
    • Create a function get_age that calculates and returns age on passing birth year. Note: You need to raise appropriate exception if birth year is in invalid format or if in future. age that is returned by function has to be integer.
  3. Implementation

    Question 3 of 3

    • You have employee record details in file employee_info.csv. Your company is hosting a party and needs to plan drink logistics. Write a program that reads the employee_info.csv file, calculates each employee's age using the previously defined function, and determines whether the employee is eligible to drink. Then generate a JSON file named drink_logistic.json in the format {"hard_drink": 5, "soft_drink": 5}, based on the number of employees who can drink and those who cannot.