小编use*_*267的帖子

TypeError“set”对象不支持项目分配

我需要知道为什么它不允许我将作业的值增加 1:

keywords = {'states' : 0, 'observations' : 1, 'transition_probability' : 2, 'emission_probability' : 3}
keylines = {-1,-1,-1,-1}

lines = file.readlines()
for i in range(0,len(lines)):
    line = lines[i].rstrip()
    if line in keywords.keys():
        keylines[keywords[line]] = i + 1 << this is where it is giving me the error
Run Code Online (Sandbox Code Playgroud)

我将它作为一个类运行,它工作得很好,但现在作为一个内联代码片段,它给了我这个错误。

python dictionary set typeerror python-3.x

5
推荐指数
2
解决办法
4万
查看次数

平均函数找不到正确的平均C++

float findGradeAvg(GradeType array, int numOfGrades)

{
    float sum = 0; 

    for (int i = 0; i < numOfGrades; i++)

       sum = sum + array[i];

    return (sum / numOfGrades); 
}
Run Code Online (Sandbox Code Playgroud)

以上是我找到输入成绩平均值的代码.功能骨架不能改变,所以我坚持使用浮动和两个输入.

这是我的主要内容:

int main()

{
    StringType30 firstname, lastname;  // two arrays of characters defined
    int numOfGrades;                   // holds the number of grades
    GradeType  grades;                 // grades is defined as a one dimensional array 
    float average;                     // holds the average of a student's grade
    char moreinput;                    // determines if there is more …
Run Code Online (Sandbox Code Playgroud)

c++

-1
推荐指数
1
解决办法
291
查看次数

标签 统计

c++ ×1

dictionary ×1

python ×1

python-3.x ×1

set ×1

typeerror ×1