我最近开始学习Python,作为一种练习,我正在研究基于文本的冒险游戏.现在,代码实际上是无效的,因为它检查用户的响应,看它是否与同一个单词的几个变体相同.我如何更改它,以便在Python 3.2中字符串检查不区分大小写?
示例代码如下:
if str('power' and 'POWER' and 'Power') in str(choice):
print('That can certainly be found here.')
time.sleep(2)
print('If you know where to look... \n')
Run Code Online (Sandbox Code Playgroud) 我正在研究Python 3.2中的一个基于文本的小冒险,因为我学习它是为了练习并且更熟悉语言.无论如何,我想这样做,以便当某些动作发生时,打印文本的颜色会发生变化.我该怎么做呢.
例如,我想要发生的第一个文本是:
if 'strength' in uniqueskill.lower():
time.sleep(3)
print('As you are a Warrior, I shall supply you with the most basic tools every Warrior needs.')
time.sleep(3)
print('A sword and shield.')
time.sleep(1)
print('You have gained A SWORD AND SHIELD!')
Run Code Online (Sandbox Code Playgroud)