# Helene Martin, Garfield High School # Computes each employee's hours worked # from an input file of work data where each line has this format: # # 123 Susan 12.5 8.1 7.6 3.2 file = open("work.txt") for line in file: tokens = line.split() id = int(tokens[0]) name = tokens[1] # cumulative sum of hours worked by this employee hours = 0.0 days = 0 for token in tokens[2:]: hours += float(token) days += 1 print name, "(ID#" + str(id) + ") worked", \ hours, "hours (" + str(hours / days), "/ day)"