我必须用python编写代码:
假设所有员工的每周工时都存储在一个表中。每行记录一名员工的七天工作小时数,共七列。例如,下表存储了八名员工的工作时数。编写一个程序,输入所有员工的工时,并按总工时的降序显示员工及其总工时。
我很难理解如何输入参数(每个员工的小时数)并存储每个参数,同时对每个参数求和。
任何帮助都将不胜感激。
发布于 2021-11-18 19:30:43
这个程序必须分解成以下几个部分
对于任务1,执行以下操作创建两个表其中一个表用于employee,它将具有列employeeid(自动编号,pkey)、fullname(文本字段)
表2以小时为单位,它将有十列,id(自动编号,pkey),employeeid(员工表的外键),day1_hour(编号字段),day2_hour(编号字段),day3_hour(编号字段),day4_hour(编号字段),day5_hour(编号字段),day6_hour(编号字段),day7_hour(编号字段),total_hour(编号字段)
然后,您需要编写一个python应用程序来插入记录,这可以在django、flask或任何您喜欢的语言中完成。
最后,将编写一个select查询( sql )来检索记录,Select语句的语法将由您使用的数据库系统决定,例如sql lite、mysql、ms sql。
发布于 2021-11-18 19:49:57
Data Sample Here: Employee vs Worked Hours
import csv
employeeDictionary = {}
currentEmployee = ''
theCSV = csv.DictReader(open('filePATH.csv'), delimiter=',') # read csv file
for theRow in theCSV:
for key, val in theRow.items(): # theRow is a dictionary
if key == 'Employee':
currentEmployee = val
employeeDictionary[currentEmployee] = [] # create dictionary entry with employeeName as key, value is a list
else:
employeeDictionary[currentEmployee].append(int(val))
employeeDictionary[currentEmployee] = sum(employeeDictionary[currentEmployee]) # once done with the row, add all hours for currentEmployee
employeeTotalHoursWorked = dict(sorted(employeeDictionary.items(), key=lambda x: x[1], reverse=True)) # sorts dictionary decreasing
print(employeeTotalHoursWorked)
https://stackoverflow.com/questions/70025385
复制相似问题