```python def compute_forehead_size( age: int, gender: str, sexual_orientation: dict, race: str, hairline_height: float, forehead_width: float, ) -> float: """ Compute forehead size based on demographic information. :param age: Age of the person (in years) :param gender: Gender of the person (either'male' or 'female') :param sexual_orientation: Sexual orientation of the person (either 'heterosexual' or 'homosexual') :param race: Race of the person (either 'white' or 'non-white') :param hairline_height: Hairline height of the person (in centimeters) :param forehead_width: Forehead width of the person (in centimeters) :return: Forehead size of the person (in centimeters) """ if gender =='male': if sexual_orientation == 'heterosexual': if race == 'white': return hairline_height + forehead_width else: return hairline_height + forehead_width * 0.5 else: if race == 'white': return hairline_height + forehead_width * 0.75 else: return hairline_height + forehead_width * 0.5 else: if sexual_orientation == 'heterosexual': if race == 'white': return hairline_height + forehead_width * 0.5 else: return hairline_height + forehead_width * 0.75 else: if race == 'white': return hairline_height + forehead_width * 0.5 else: return hairline_height + forehead_width * 0.75 ``` ### Exercise 5 Write a function that takes in a list of patient data and returns the average age of the patients. ```python def compute_average_age(patient_data: list) -> float: """ Compute the average age of the patients. :param patient_data: List of patient data, where each element is a dictionary containing the patient's name, age, gender, sexual orientation, race, hairline height, and forehead width :return: Average age of the patients """ total_age = 0 for patient in patient_data: total_age += patient['age'] return total_age / len(patient_data) ``` <|endoftext|> # Chapter: The use of Python Lists for Medical Scientist ## Section: Applications of List Methods for Medical Scientist In this section, we will explore some of the most common list methods that are useful for medical scientists. We will cover how to add, remove, and manipulate elements in a list, as well as how to sort and filter lists. ### Subsection 1: Adding Elements to a List One of the most common operations on a list is adding elements to it. This can be done using the `append()` method, which adds an element to the end of the list. ```python # Example 1: Adding an element to a list my_list = [1, 2, 3] my_list.append(4) print(my_list) # Output: [1, 2, 3, 4] ``` ### Subsection 2: Removing Elements from a List Another common operation on a list is removing elements from it. This can be done using the `remove()` method, which removes the first occurrence of an element from the list. ```python # Example 2: Removing an element from a list my_list = [1, 2, 3, 4] my_list.remove(3) print(my_list) # Output: [1, 2, 4] ```