文字游戏-将输入文字转换为小写字母-Python 3.0 [英] Text Game - Convert input text to lowercase - Python 3.0
问题描述
((对于以上编辑,以上链接未回答.以上问题与我的预期用途无关.)
((In response to the above edit, this was not answered in the above link. The above question is irrelevant to my intended use.))
我读过一个类似的问题,关于将字符串转换为小写字母;
I have read a similar question about turning a string into lowercase;
我了解这是如何完美运行的,但是我自己的尝试失败了.
I understand how this works perfectly, however my attempts at this myself have failed.
这是我当前的调试块设置示例;
Here's my current setup example for a debug block;
#Debug block - Used to toggle the display of variable data throughout the game for debug purposes.
def debug():
print("Would you like to play in Debug/Developer Mode?")
while True:
global egg
choice = input()
if choice == "yes":
devdebug = 1
break
elif choice == "Yes":
devdebug = 1
break
elif choice == "no":
devdebug = 0
break
elif choice == "No":
devdebug = 0
break
elif choice == "bunny":
print("Easter is Here!")
egg = 1
break
else:
print("Yes or No?")
#
因此,我已预先编写了使用其他大写字母的代码.但是,我只想每个单词只使用一个if
语句,而不要使用两个大写字母.我确实有个主意,可以使用另一个代码块来确定True的False状态; </p>
So, I have it prewritten to work with a different capitalization. However, I'd like to use only one if
statement per word rather than using two for the capitalization. I do have an idea, that uses another block to determine a True of False state, which would look like this;
def debugstate():
while True:
global devstate
choice = input()
if choice == "Yes":
devstate = True
break
elif choice == "yes":
devstate = True
break
elif choice == "No":
devstate = False
break
#Etc Etc Etc
但是使用此块只会占用我已经拥有的代码行,然后将其移动到其他地方.我知道我可以进行设置,如果不是'Yes',则else可以自动将devstate设置为0,但是我更喜欢具有更可控的环境.我不想不小心用空格输入'yes'并关闭devmode.
But using this block would just take the lines of code I already have, and move it somewhere else. I know I could set it up that if it isn't 'Yes' then the else can automatically set devstate to 0, but I prefer to have a more controlled environment. I don't want to accidentally type 'yes ' with a space and have devmode off.
回到问题;
我将如何做到这一点,以便我可以执行以下操作?
How would I make it so I can just do the following?
def debug():
print("Debug Mode?")
while True:
global egg
choice = input()
if choice == "yes" or "Yes":
devdebug = 1
break
elif choice == "no" or "No":
devdebug = 0
break
elif choice == "egg":
devdebug = 0
egg = 1
print("Easter is Here")
break
else:
print("Yes or No?")
#
上面的代码可能不是最好的例子,但是当我说我每个单词只想要一个if
语句时,它至少可以帮助我理解我的观点. (此外,我希望我不只是在xD上解决自己的问题.)
The above code probably isn't the best example, but it at least helps me get my point across when I say I only want one if
statement per word. (Also, I hope I didn't just solve my own problem here xD.)
那么,我该怎么做?
((此外,我之所以来到这里而不是Python论坛的原因是,我更喜欢以自己的方式提出问题,而不是试图从一个措辞不同的问题中拼凑出答案).)
((Also, the reason I go here rather than the Python forums is because I prefer to ask my question in my own way rather than trying to piece together an answer from a question that was worded differently for someone else.))
推荐答案
使用.lower()是您的最佳选择
Using .lower() is your best option
choice = input()
choice = choice.lower()
if choice == 'yes':
dev_debug = 1
break
或使用中"
choice = input()
if choice in ('yes', 'Yes'):
dev_debug = 1
break
这篇关于文字游戏-将输入文字转换为小写字母-Python 3.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!