Error Handling
✕Error Handling
Question 1 of 3
- Write a function that takes a string and returns number of lowercase characters in it. Ensure
TypeErroris handled. - Write a function that takes mass in kg and volume in cubic meter and returns density. Ensure
ZeroDivisionErrorandTypeErroris handled. - Write a function
get_namethat accepts a dictionary and returns the value of keyname. EnsureKeyErroris handled. - Write a function
get_third_elementthat accepts a list and returns the third element. EnsureIndexErroris handled.
- Write a function that takes a string and returns number of lowercase characters in it. Ensure
Raising Error
Question 2 of 3
- Write a function
can_drinkthat takes age and checks if user can drink. If user is 18+, return True else return False. Note: You need to raiseTypeErrorif age is not integer value,ValueErrorif age is below 0,AssertionErrorif age is above 100. - Create a function
get_agethat 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.agethat is returned by function has to be integer.
- Write a function
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 theemployee_info.csvfile, calculates each employee's age using the previously defined function, and determines whether the employee is eligible to drink. Then generate a JSON file nameddrink_logistic.jsonin the format{"hard_drink": 5, "soft_drink": 5}, based on the number of employees who can drink and those who cannot.
- You have employee record details in file
