# Kids2 Example # Source code file: kids2.py # Input file: kids.txt # Compute the average of all the girls. # To compute the average, keep track of # the sum and the count of the grades, # but only use the lines where gender == "F". sum = 0 count = 0 fin = open("kids.txt", "r") # Read first line from file line = fin.readline( ) # Process lines until end of file while line != "": fields = line.split(",") name = fields[0].strip( ) gender = fields[1].strip( ) age = int(fields[2].strip( )) if gender == "F": sum = sum + age count = count + 1 line = fin.readline( ) print("Average of ages:", round(sum / count, 2)) fin.close( ) # Output: # Average of girl's ages: 9.33