为什么一直显示菜单?-python
我试着做一些东西,如果你在m中输入,它会给你一个菜单,如果你只按enter键,它会继续为什么一直显示菜单?-python,python,Python,我试着做一些东西,如果你在m中输入,它会给你一个菜单,如果你只按enter键,它会继续 menu = False while True: option = input('Press M for menu, and press enter to continue') if option == 'm' or 'M': menu = True while menu: print('MENU') #there
menu = False
while True:
option = input('Press M for menu, and press enter to continue')
if option == 'm' or 'M':
menu = True
while menu:
print('MENU')
#theres some stuff here but thats not important
else:
print('Continuing...')
但是,每当我运行它时,它总是转到菜单屏幕
if option == 'm' or 'M'
这里的选项=='m'或'm'
是一个布尔表达式,它的计算结果始终为True,因为'm'
将始终不是None。把它改成
if option.lower()=='m':
如果选项='m'或'm',请再次选中
:
。它将把'M'
计算为True<代码>如果选项=='m'或选项=='m':