在Python中,给定以下上下文的语句的语法是什么:
words = 'blue yellow'
Run Code Online (Sandbox Code Playgroud)
将是一个if语句,检查是否words
包含单词"blue"?也就是说,
if words ??? 'blue':
print 'yes'
elif words ??? 'blue':
print 'no'
Run Code Online (Sandbox Code Playgroud)
在英语中,"如果单词包含蓝色,则说是.否则,打印否."
就像我在python中一样.
choice1 = raw_input('John Blue Green')
if choice1 == 'A':
print('blah')
elif choice1 == 'B':
print('blahblah')
Run Code Online (Sandbox Code Playgroud)
有人进入B但不正确所以我希望它回去再问一次.我怎么做?当心,我是一个编程菜鸟.
def Forest(Health,Hunger):
print'You wake up in the middle of the forest'
Inventory = 'Inventory: '
Squirrel = 'Squirrel'
while True:
Choice1 = raw_input('You...\n')
if Choice1 == 'Life' or 'life':
print('Health: '+str(Health))
print('Hunger: '+str(Hunger))
elif Choice1 == 'Look' or 'look':
print 'You see many trees, and what looks like an edible dead Squirrel, \na waterfall to the north and a village to the south.'
elif Choice1 == 'Pickup' or 'pickup':
p1 = raw_input('Pickup what?\n')
if p1 == Squirrel:
if Inventory == …
Run Code Online (Sandbox Code Playgroud) 如何删除字符串的一部分
Blue = 'Blue '
Yellow = 'Yellow'
Words = Blue + Yellow
if Blue in Words:
Words = Words - Yellow
Run Code Online (Sandbox Code Playgroud)
这就是我认为的样子?
编辑:我知道这不起作用我想知道什么会起作用.因为你不能在str()中使用' - '