【发布时间】:2016-06-12 21:13:38
【问题描述】:
为什么SchoolData[1][1](用户名或分数等)总是给出0?
score=0
Class = 0
for x in range (0,3): # the number of times I want the user to complete the quiz
print ("Enter your name")
name = input()
print ("what class")
Class = input()
print("1. 9+10=")
answer = input()
answer = int(answer)
if answer == 19:
print("correct")
score = score + 1
else:
print("wrong")
print("2. 16+40=")
answer = input()
answer = int(answer)
if answer == 56:
print("correct")
score = score + 1
else:
print("wrong")
print("3. 5+21=")
answer = input()
answer = int(answer)
if answer == 26:
print("correct")
score = score + 1
else:
print("wrong")
print("4. 5-6=")
answer = input()
answer = int(answer)
if answer == -1:
print("correct")
score = score + 1
else:
print("wrong")
print("5. 21-9=")
answer = input()
answer = int(answer)
if answer == 12:
print("correct")
score = score + 1
else:
print("wrong")
SchoolData=[[0 for x in range(3)] for x in range(3)] #this is the array
SchoolData[x][0]=name #this is the users name enter code here
SchoolData[x][1]=score #this is the score obtained by the user
SchoolData[x][2]=Class #this is the users class number
raise SystemExit
我运行代码并完成了 3 次测验。我想知道第一个用户的姓名、分数和班级编号。我尝试从数组中的单元格中提取信息。
【问题讨论】:
-
我认为您有意图问题, SchoolData=[[...]] 及以下行需要在 for 循环内。您希望 SchoolData 是什么样子?
-
所以当我输入例如让我说我想知道(当测验由 3 个不同的用户运行 3 次时)第一个用户的姓名或分数或类 1。例如我是我只想通过从数组中提取该信息来了解这个和这个学生的分数和他们的名字。
标签: python loops python-3.x for-loop multidimensional-array