当前位置: 代码迷 >> python >> 带有 if 的多个条件
  详细解决方案

带有 if 的多个条件

热度:120   发布时间:2023-06-13 20:26:24.0

我正在尝试检查if...and语句是否满足两个条件:

if foo < 0 and bar < 0:
    #do something

但它总是回归积极。 为什么?

这是完整的代码:

loop = 1
while loop == 1:
    t = raw_input("Please enter a number.")
    d = raw_input("Please enter another number")
    limit = raw_input("Please enter another number")
    try:
        t = int(t)
        d = int(d)
        limit = int(limit)
        loop = 0
    except ValueError:
        print "Sorry, but one of those was an invalid input. Please ensure you enter only numbers greater than zero."
    if t > 0 and d > 0:
        loop = 0
    else:
        pass

你在foobar的值到底是什么?
工作示例:

a = 'True' 
b = 'True'

if (a and b):
    print('Both True')

c = 'Hello'
d = 'Hello'

if (c == d):
    print('Equal')
  相关解决方案