【发布时间】:2021-11-22 12:29:11
【问题描述】:
目标:分别找到每个科目的最佳得分手。分数在整个 int(input()) 中接收。
示例
数学:[0 20 30 40 50 ] 输出:“最佳分数:50”
英文:[0 40 50 80 90 ] 输出:“Best Score: 80”
科学:[0 90 78 90 97] 输出:“最佳分数:97”
问题:即使我使用了 copy() 或 list[:],计算机仍将复制的代码识别为整数对象,而不是列表。
输入代码:完全正确
问题所在的代码:
subject_score = [0, 0, 0, 0, 0]
a, b, c = subject_score[:]
i = 0
for subject in midterm_score:
for i in range(0, len(subject_score) - 1):
a[i] = midterm_score[0][i]
b[i] = midterm_score[1][i]
c[i] = midterm_score[2][i]
minscore1 = a[0]
for i in range(1, len(subject_score) - 1):
if minscore1 < a[i]:
minscore1 = a[i]
minscore2 = b[0]
for i in range(1, len(subject_score) - 1):
if minscore2 < b[i]:
minscore2 = b[i]
minscore3 = c[0]
for i in range(1, len(subject_score) - 1):
if minscore3 < c[i]:
minscore3 = c[i]
print(a, b, c)
print("Math:"+ minscore1)
print("English:" + minscore2)
print("Science:"+ minscore3)
出现问题的地方:
subject_score = [0, 0, 0, 0, 0]
a, b, c = subject_score[:]
程序员的能力:菜鸟
回答者:会有美好的一天
谢谢。
【问题讨论】:
-
您希望变量 a、b 和 c 包含什么?
[0,0,0,0,0]? -
首先,在将 subject_score 分配给 a、b 和 c 时,您应该得到一个 valueError。如果要将 subject_score 分配给 a、b 和 c,以便 a、b 和 c 成为列表,则必须单独执行。类似于 a = score[:];b = score[:];c=score[:]
标签: python list integer traceback