为什么'!='和'=='在python中的while或for循环中不起作用

时间:2020-09-19 05:35:44

标签: python python-3.x loops for-loop while-loop

没有循环!=和==起作用,但是如果我将它们放入循环中,它们将不起作用

a = int(input())
while a != 'stop':
x = int(input())
y = str(input())
z = str(input())
if x == 'A':
    x = a
    if y == z:
        a = a + x
    elif y != z:
        a = a - x

3 个答案:

答案 0 :(得分:1)

Dude python关心缩进。您要在while循环中循环的每一行都应缩进。尝试缩进代码,然后重试

答案 1 :(得分:0)

我无论如何都不是专家,但缩进可能是问题所在。

答案 2 :(得分:0)

此修复程序可能已添加缩进:

a = int(input())
while a != 'stop':
   x = int(input())
   y = str(input())
   z = str(input())
   if x == 'A':
     x = a
     if y == z:
        a = a + x
     elif y != z:
        a = a - x