我需要知道为什么它不允许我将作业的值增加 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)
我将它作为一个类运行,它工作得很好,但现在作为一个内联代码片段,它给了我这个错误。
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)