问题
如果语句允许一个条件通过,即使它不符合参数
描述
当所选内容等于列表操作的索引2或列表的索引3时,应该运行这段代码。然而,当selection等于列表操作的索引1时,代码仍在运行
if v.selection == v.operations[2] or v.operations[3]:
print('arrived at a sub n missing - geometric')
print('index of ', v.selection, 'in the list is ', v.operations.index(v.selection))
if not v.aSub1:
v.aSub1 = input('first value in sequence>>>')
if not v.r:
v.r = input('common rate>>>')
if not v.n:
v.n = input('index (n)>>>')
pass
pass
pass
你从错误的角度看if语句。 你写的是: v.selection等于v.operations[2]或v.operations[3]都不是false。 就这点而言,任何不是0的东西都不是假的。 举个例子:
结果是:
相关问题 更多 >
编程相关推荐