def get_average_age(): data_headers = list(hr.data_read()) data = data_headers[0] headers = data_headers[1] j = 0 birthdays = [] for i in data: elements = data[0 + j] dates = elements[2] date = dates.split("-") birthdays.append(date) j += 1 a = 0 years = [] for day in birthdays: elem = birthdays[0 + a] year = elem[0] years.append(int(year)) a += 1 ages = [] for elem in years: age = 2020 - elem ages.append(age) average = sum(ages) / len(ages) print("The average age of employees is:") print(round(average, 2))
def get_oldest_and_youngest(): data_headers = list(hr.data_read()) data = data_headers[0] headers = data_headers[1] print(len(data)) j = 0 birthdays = [] for i in data: elements = data[0 + j] dates = elements[2] date = dates.split("-") birthdays.append(date) j += 1 a = 0 years = [] for day in birthdays: elem = birthdays[0 + a] year = elem[0] years.append(int(year)) a += 1 oldest = min(years) youngest = max(years) index = years.index(oldest) index_young = years.index(youngest) print("The oldest employee is:") view.print_table([data[index]], headers) print("") print("The youngest employee is:") view.print_table([data[index_young]], headers)
def add_employee(): data = list(hr.data_read()) data = data[0] ID = hr.get_ID() name = input("Enter name:\n") date_of_birth = input("Enter date of birth:\n") department = input("Enter department:\n") clearance = input("Enter level of clearance:\n") adding = [ID, name, date_of_birth, department, clearance] data.append(adding) hr.data_write(data)
def delete_employee(): data_headers = list(hr.data_read()) data = data_headers[0] to_del = int(input("Select employee to delete:\n")) del data[to_del - 1] hr.data_write(data)
def list_employees(): data_headers = list(hr.data_read()) data = data_headers[0] headers = data_headers[1] view.print_table(data, headers)