Machine Learning: Take into account a variable if a condition is met (depending on another variable)
If you are interested to see if there are any other girls, you'll likely need to create a new indicator variable in your modelling data - perhaps something like:


other_girls_in_class = 1 if gender = female and there are other girls in the class
other_girls_in_class = 0 if gender = female and there are no other girls in the class


You need to treat these kind of approaches with care as it will implicitly contain some information on student gender.