Introduction to Programming using Python 1st Edition

Published by Pearson
ISBN 10: 0132747189
ISBN 13: 978-0-13274-718-9

Chapter 11 - Multidimensional Lists - Programming Exercises - Page 382: 11.4

Answer

code

Work Step by Step

# 11.4 (Compute the weekly hours for each employee) Suppose the weekly hours for all # employees are stored in a table. Each row records an employee’s seven-day work # hours with seven columns. For example, the following table stores the work hours # for eight employees. Write a program that displays employees and their total hours # in decreasing order of the total hours. workHours = [ [2, 4, 3, 4, 5, 8, 8], [7, 3, 4, 3, 3, 4, 4], [3, 3, 4, 3, 3, 2, 2], [9, 3, 4, 7, 3, 4, 1], [3, 5, 4, 3, 6, 3, 8], [3, 4, 4, 6, 3, 4, 4], [3, 7, 4, 8, 3, 8, 4], [6, 3, 5, 9, 2, 7, 9]] matrix = [] for row in range(len(workHours)): totHours = sum(workHours[row]) matrix.append([totHours, "Employee " + str(row)]) matrix.sort(reverse=True) for i in matrix: print(i[1]+"'s total hours =", i[0])
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.