我需要人帮我把表格打印出来。我希望它打印为:
Name TotalHours
Jenny 34
Luke 28
Mike 20
Joanne 31
Tom 34
但是,这种情况会发生在-> enter image description here上
这是我的代码:
hrs_list = [[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]]
employees = ['Jenny', 'Luke', 'Mike', 'Joanne', 'Tom']
def total_hrs_and_salary():
print("{} {:>15s} {:>15s}".format("Name", "TotalHours", "TotalSalary"))
for names in employees:
for lists in hrs_list:
total = 0
a = []
i = 0
for hrs in lists:
total = total + hrs
print("{} {:>15s}".format(names, total))
发布于 2020-07-01 12:25:02
你可以这样打印它:
def total_hrs_and_salary():
print("name\tTotalHours\n")
for i, name in enumerate(employees):
print(f"{name}\t{sum(hrs_list[i])}\n")
total_hrs_and_salary()
输出:
name TotalHours
Jenny 34
Luke 28
Mike 20
Joanne 31
Tom 32
https://stackoverflow.com/questions/62676448
复制相似问题