小编Joh*_*ith的帖子

确定字符串是否包含单词

在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 if-statement

4
推荐指数
3
解决办法
1万
查看次数

重新启动if then语句

就像我在python中一样.

choice1 = raw_input('John Blue Green')
if choice1 == 'A':
   print('blah')
elif choice1 == 'B':
   print('blahblah')
Run Code Online (Sandbox Code Playgroud)

有人进入B但不正确所以我希望它回去再问一次.我怎么做?当心,我是一个编程菜鸟.

python if-statement

2
推荐指数
1
解决办法
163
查看次数

逻辑或运算符的行为不符合预期

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)

python if-statement logical-or

0
推荐指数
1
解决办法
168
查看次数

从其他字符串中删除字符串

如何删除字符串的一部分

Blue = 'Blue '
Yellow = 'Yellow'
Words = Blue + Yellow
if Blue in Words:
    Words = Words - Yellow
Run Code Online (Sandbox Code Playgroud)

这就是我认为的样子?

编辑:我知道这不起作用我想知道什么会起作用.因为你不能在str()中使用' - '

python if-statement

0
推荐指数
1
解决办法
60
查看次数

标签 统计

if-statement ×4

python ×4

logical-or ×1