/**
 * Given a dictionary containing the data of patients, this function calculates and returns the average age of all the male patients.
 *
 * @param patientsData A dictionary where the keys are patient IDs and the values are dictionaries containing their data.
 * @return The average age of the male patients.
 */
fun calculateAverageAge(patientsData: Map<String, Map<String, Any>>): Double {

    val maleAges = mutableListOf<Int>() // Initialize an empty list to store the ages of male patients

    for ((_, patientData) in patientsData) {
        if (patientData["gender"] == "male") {
            maleAges.add(patientData["age"] as Int)
        }
    }

    if (maleAges.isEmpty()) {
        return 0.0 // Return 0 if there are no male patients
    } else {
        val totalAge = maleAges.sum()
        val numMalePatients = maleAges.size
        val averageAge = totalAge.toDouble() / numMalePatients
        return averageAge
    }
}
/**
 * Given a dictionary containing the data of patients, this function calculates and returns the average age of all the male patients.
 *
 * @param patientsData A dictionary where the keys are patient IDs and the values are dictionaries containing their data.
 * @return The average age of the male patients.
 */
fun calculateAverageAge(patientsData: Map<String, Map<String, Any>>): Double {
/**
 * Given a dictionary containing the data of patients, this function calculates and returns the average age of all the male patients.
 *
 * @param patientsData A dictionary where the keys are patient IDs and the values are dictionaries containing their data.
 * @return The average age of the male patients.
 */
fun calculateAverageAge(patientsData: Map<String, Map<String, Any>>): Double {

    val maleAges = mutableListOf<Int>() // Initialize an empty list to store the ages of male patients

    for ((_, patientData) in patientsData) {
        if (patientData["gender"] == "male") {
            maleAges.add(patientData["age"] as Int)
        }
    }

    if (maleAges.isEmpty()) {
        return 0.0 // Return 0 if there are no male patients
    } else {
        val totalAge = maleAges.sum()
        val numMalePatients = maleAges.size
        val averageAge = totalAge.toDouble() / numMalePatients
        return averageAge
    }
}