input: Write a function to calculate the average age of students with given grades.
  assert calculate_average_age([{'name': 'John', 'grade': 10, 'age': 10}, {'name': 'Jane', 'grade': 8, 'age': 14}, {'name': 'Kate', 'grade': 9, 'age': 12}], [10, 8, 9]) == 12.0
  assert calculate_average_age([{'name': 'Alice', 'grade': 5, 'age': 11}, {'name': 'Bob', 'grade': 6, 'age': 12}, {'name': 'Carol', 'grade': 5, 'age': 10}], [5, 6]) == 11.0
  assert calculate_average_age([{'name': 'Dan', 'grade': 7, 'age': 13}, {'name': 'Eve', 'grade': 8, 'age': 14}, {'name': 'Frank', 'grade': 9, 'age': 15}], [7, 8, 9]) == 14.0
output: def calculate_average_age(students, grades):
      selected_students = [student for student in students if student['grade'] in grades]
      if not selected_students:
          return 0
      total_age = sum(student['age'] for student in selected_students)
      return total_age / len(selected_students)