Python类未定义

2024-09-30 18:25:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在自学IGCSE计算机科学(可以编程),但我与数组的问题

我的书以这个代码为例

import array

NoStudents = int(30)
Studentmarktest = array.array ('i',range(NoStudents+1))
for i in range(0,30):   
    Studentmarktest[Counter] = int(input("Enter students score"))
print (Studentmarktest)

但是这个例子返回:NameError: name 'Counter' is not defined


Tags: 代码inimportfor编程counterrange数组
1条回答
网友
1楼 · 发布于 2024-09-30 18:25:51

看看你的代码

for i in range(0,30):   
    Studentmarktest[Counter] = int(input("Enter students score"))

您使用i作为循环的索引变量。但在循环中,您使用的是Counter。你只需改变这一点:

for i in range(0,30):   
    Studentmarktest[i] = int(input("Enter students score"))

相关问题 更多 >