Function 如何添加一个参数的多个实例,使其成为代码中的某个变量,并将该参数作为函数中的一个参数使用
嘿,伙计们,在函数中传递了进程、移位和学习曲线级参数之后,我的代码给出了速率。有7个班次,现在我想做的是,我想做从A到E的白班,从F到G的夜班,总共9个班次,但我不知道怎么做。任何建议都会很有帮助Function 如何添加一个参数的多个实例,使其成为代码中的某个变量,并将该参数作为函数中的一个参数使用,function,csv,Function,Csv,嘿,伙计们,在函数中传递了进程、移位和学习曲线级参数之后,我的代码给出了速率。有7个班次,现在我想做的是,我想做从A到E的白班,从F到G的夜班,总共9个班次,但我不知道怎么做。任何建议都会很有帮助 import csv def Calc(process, shift, lc): f = open('C:\\Users\\keshabg\\Desktop\\sql_testing\\table_1.csv') csv_f = csv.reader
import csv
def Calc(process, shift, lc):
f = open('C:\\Users\\keshabg\\Desktop\\sql_testing\\table_1.csv')
csv_f = csv.reader(f)
res_units = []
res_hours = []
sum_units = 0
sum_hours = 0
for row in csv_f:
if row[2] == shift and row[3] == process and row[4] == lc:
res_units.append(row[5])
res_hours.append(row[6])
for num in res_units:
sum_units = float(sum_units) + float(num)
for num in res_hours:
sum_hours = float(sum_hours) + float(num)
try:
res_rate = round(sum_units/sum_hours, 2)
except ZeroDivisionError:
res_rate = "N/A"
return "The Units Processed was: ", res_units , "The Hours worked was: " , res_hours , "The total units was: " , sum_units , "The total hours was: " , sum_hours , "The rate: " , res_rate
import csv
def Calc(process, shift, lc):
if shift == 'day':
shift = ['A','B','C','D','E']
if shift == 'night':
shift = ['F','G']
f = open('C:\\Users\\keshabg\\Desktop\\sql_testing\\table_1.csv')
csv_f = csv.reader(f)
res_units = []
res_hours = []
sum_units = 0
sum_hours = 0
for row in csv_f:
if row[2] in shift and row[3] == process and row[4] == lc:
res_units.append(row[5])
res_hours.append(row[6])
for num in res_units:
sum_units = float(sum_units) + float(num)
for num in res_hours:
sum_hours = float(sum_hours) + float(num)
try:
res_rate = round(sum_units/sum_hours, 2)
except ZeroDivisionError:
res_rate = "N/A"
return "The Units Processed was: ", res_units , "The Hours worked was: " , res_hours , "The total units was: " , sum_units , "The total hours was: " , sum_hours , "The rate: " , res_rate