我有这个密码:
def begin(): # the main attraction.
print("Select difficulty level\n")
print("E - Easy. Data set is 5 numbers long, and the set is sorted\n")
print("M - Medium. Data set is 7 numbers long and the set is sorted\n")
print("H - Hard. Data set is 10 numbers long and the set is not sorted\n")
difficultySelect = input()
if difficultySelect == "E" or "e":
worksheet.beginGameLoop("easy")
elif difficultySelect == "M" or "m":
worksheet.beginGameLoop("med")
elif difficultySelect == "H" or "h":
worksheet.beginGameLoop("hard")
def beginGameLoop(gameDifficulty):
if gameDifficulty == "easy":
length = 5
sorting = True
elif gameDifficulty == "med":
length = 7
sorting = True
elif gameDifficulty == "hard":
length = 10
sorting = False
for questions in range(10):
invalidPrinted = False
questions, answer, qType = worksheet.createQuestion(length, sorting)
当我运行它时,它似乎被简单模式的变量卡住了。有什么问题吗? 编辑:整件事是here.
看起来你的
for
循环缩进太远了。你知道吗问题在于:
应该是:
或者更好:
语句
if x == 'a' or 'b'
将始终为真。在Python中,or
语句的结果是False
或不是False
的第一个求值语句的值。所以在你的例子中,如果difficultySelect
等于E
,它就是True
,或者e
。而且e
总是不是False
——这就是为什么第一个条件总是被满足的原因。你知道吗相关问题 更多 >
编程相关推荐