d是很大的列表数据集,这个代码无法实现想要的后面的结果,要么是str和float的转换,要么就是只有佳作一个结果。
i=0
for i in range(len(d)):
i=i+1
s=float(d[i][2])
if s<0 or s> 10.0:
s='无效评分'
elif s< 6.0:
s='不及格'
elif s >= 6.0 and s<8.0:
s='还可以'
elif s>=8.0 and s<= 9.0:
s='优秀'
else:
s='佳作'
break
print(s)
q=['剧情/犯罪', '美国',7.6], ['剧情/动作/犯罪', '法国', 9.5]
for i in range(2):
s=float(q[i][2])
if s> 9.0:
q[i][2]='佳作'
else:
q[i][2]='差'
print(list[q])
想要的结果:修改数值:list[['剧情/犯罪', '美国', '差'], ['剧情/动作/犯罪', '法国', '佳作']]
movie_list = [['剧情/犯罪', '美国', 7.6], ['剧情/动作/犯罪', '法国', 9.5], ['剧情/动作/犯罪', '法国', 2.5], ['剧情/动作/犯罪', '法国', -9.5],
['剧情/动作/犯罪', '法国', 19.5, ], ['剧情/动作/犯罪', '法国', 8.5]]
for i in movie_list:
score = i[2]
if score < 0 or score > 10:
index = movie_list.index(i)
movie_list[index][2] = '无效分数'
elif score > 9:
index = movie_list.index(i)
movie_list[index][2] = '佳作'
elif score > 8:
index = movie_list.index(i)
movie_list[index][2] = '优秀'
elif score > 6:
index = movie_list.index(i)
movie_list[index][2] = '一般'
elif score < 6:
index = movie_list.index(i)
movie_list[index][2] = '不及格'
print(movie_list)