我正在尝试完成有关pygame的计算机编程课程的作业;我对这种事情不是很精通,所以请问我在问问题时犯一些错误。
我正在尝试从我们的教科书中修改一些源代码,目的是允许用户设置一组块在窗口中移动的速度以及位置更新之间的延迟。程序的开头是一个while循环,旨在让用户在预定设置之间进行选择,或者创建自己的设置。
choice = ""
while choice != "E" or "e" or "Elect" or "elect" or "ELECT" or "C" or "c" or "Create" or "create" or "CREATE" :
choice = input("Would you like to elect a speed setting for the vectors, or create your own? (Type 'E' for elect or 'C' for create) ")
当我尝试在shell中运行该程序时,在键入“ e”时,它再次为while循环提供了输入语句。为什么未将“选择”设置为我的输入?
尝试:
choice = ""
while choice.lower() not in ("e", "elect", "c", "create"):
choice = input("Would you like to elect a speed setting for the vectors,, create your own? (Type 'E' for elect, 'C' for create) ")
为什么
你的问题是choice != "E" or "e" or ...
手段(choice != "E") or ("e") or (...)
。而"e"
计算结果为True
,因为它不是None
,0
,False
,或空序列。因此,您的条件始终为true。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句