我无法使用用户输入从扩展列表中跳出。我想我缺少了如何使用if
语句来查询特定项的列表。当用户输入-999时,我需要一个列表来请求输入。我还需要从列表中排除-999。你能帮助我吗?你知道吗
print(scoreLst)
就是为了在我使用它时可以测试和查看它是如何工作的。你知道吗
scoreLst =[]
score = ()
lst1 = True
print("The list ends when user inputs -999")
scoreLst.append(input("Enter the test score: "))
while lst1 == True:
score1 = scoreLst.append(input("Enter another test score: "))
print(scoreLst)
if score1 != -999:
lst1 == True
else:
scoreLst.remove(-999)
lst1 == False
注意事项:
将考试成绩转换为
int
list.append
返回None
,不要将它赋给任何对象;使用scoreLst[-1]
而不是score1
不要使用
list.remove
删除列表的最后一个元素,list.pop()
将很好地工作lst1 == False
是比较,lst1 = False
是赋值您将创建一个无限循环,
break
一旦用户输入-999,我认为没有必要lst1
最终结果:
相关问题 更多 >
编程相关推荐