我试图找到高于标准偏差的人和他们的平均成绩。我的问题是,当它试图将名称与得分相匹配时,它的说法是“第75行,在 在= nameList.index(eachStudent) ValueError:84.0不在列表中。。但是数字在列表中。
app.directive('employeeName', ['employeeService', function (employeeService) {
return {
restrict: 'A',
require: 'ngModel',
link: function (scope, elem, attrs, ctrl) {
employeeService.getAll()
.then(function (data) {
$(elem).devbridgeAutocomplete({
lookup: $.map(data, function (employee, i) {
return { value: employee.name, data: employee };
}),
onSelect: function () {
console.log('select');
update();
},
onInvalidateSelection: function () {
$(this).val('');
}
});
});
elem.on('blur', function () {
console.log('blur');
update();
});
var update = function () {
var value = elem[0].value;
scope.$apply(function () {
ctrl.$setViewValue(value);
ctrl.$render();
});
console.log(value);
console.log(ctrl.$modelValue)
console.log(scope.organizer);
};
}
};
}]);
答案 0 :(得分:1)
84.0 不在 nameList
中示例:的
In [6]: x = [4,6,7]
In [7]: x.index(6)
Out[7]: 1
In [8]: x.index(8)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-8-67db2e8075c7> in <module>()
----> 1 x.index(8)
ValueError: 8 is not in list
答案 1 :(得分:1)
我假设
那怎么样:
i = 0
for eachScore in scoreList:
if eachScore > x:
count+=1
In.append(nameList[i])
i+=1
答案 2 :(得分:0)
您可以确定eachStudent
列在scoreList
列表中,但您确定它在nameList
列表中吗?从您的代码摘录中可以清楚地看出这一点。