我的代码在哪里出错?我正在寻找男女收入的差异?这是我的代码:
names.append(players['firstName'] + ' ' + players['lastName'])
答案 0 :(得分:2)
您可以尝试以下方法:
for x in range (0,len(occupation_lst)):
col_occ = occupation_lst[x]
col_m = m_weekly_lst[x]
col_f = f_weekly_lst[x]
diff = abs(col_m - col_f)
if col_m > col_f:
status = "Female workers make $" + str(diff) + "/week less than Female workers."
elif col_m < col_f:
status = "Female workers make $" + str(diff) + "/week more than Male workers."
else:
status = "Both Male and Female workers make same amount of salary $" + str(diff)
print (col_occ + ": " + status)
答案 1 :(得分:0)
如果只想了解这两个列表之间的区别,可以使用 zip 函数。
diff_income= [abs(x - y) for x, y in zip(m_weekly_lst, f_weekly_lst)]
print(diff_income)