# Employees2 Example # Source code file: employees1.py # Input file: employees.txt # Fields in employees.txt input file: # Name,Gender,Age,City,Salary # Note that these fields are shown in the # first line of the input file. This line # must be read and thrown away before # processing the data lines. sum = 0 count = 0 fin = open("employees.txt", "r") # Read and throw away first line: fin.readline( ) # Read second 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( )) city = fields[3].strip( ) salary = float(fields[4].strip( )) if city == "Chicago": sum = sum + salary count = count + 1 line = fin.readline( ) print("Average of Chicago salaries:", round(sum / count, 2)) fin.close( ) # Output: # Average of Chicago salaries: 65285.71