小编m.b*_*ter的帖子

在Python中使用'not'和'or'

在Python 2.5中,我使用了代码:

    yn=raw_input('''This program is for solving linear and quadratic equations.
    Is this what you want to do?
    ''')
    if not 'y' in yn or 'Y' in yn:
        print 'Program now quitting.'
Run Code Online (Sandbox Code Playgroud)

Program now quitting当程序关闭时显示,当yn不包含'y'或'Y'时应该显示,但是当yn确实包含'Y'时,它也显示在程序的其余部分开始之前.我认为错误是通过使用"或",造成"不"在一起,因为它并没有改变,当我改变if not 'y' in yn or 'Y' in yn:if not 'y' in yn or not 'Y' in yn:,但消失时,我把它改成

    if not 'y' in yn:
        if not 'Y' in yn:
Run Code Online (Sandbox Code Playgroud)

这是正确的吗?如果有的话,我可以做些什么来解决问题并将这部分保持在同一条线上?

python python-2.5

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

标签 统计

python ×1

python-2.5 ×1