Python 3“elif”无法正常工作

时间:2015-03-30 12:05:53

标签: python

我是Python 3的新手,我已经开始学习If语句,但是当我运行代码时,它说“elif”无法识别?

intE = 20

if intE < 20:
    print("Value is less than 20")
    elif intE > 20:
        print("Value is more than 20")
        else:
            print("Value is 20")

3 个答案:

答案 0 :(得分:4)

问题是你的缩进

intE = 20

if intE < 20:
    print("Value is less than 20")
elif intE > 20:
    print("Value is more than 20")
else:
    print("Value is 20")

答案 1 :(得分:1)

在python中,所有关于缩进的内容:) ifelifelse必须位于同一列中:

intE = 20

if intE < 20:
    print("Value is less than 20")
elif intE > 20:
    print("Value is more than 20")
else:
    print("Value is 20")

答案 2 :(得分:0)

实际上它应该是:

intE = 20

if intE < 20:
    print("Value is less than 20")
elif intE > 20:
    print("Value is more than 20")
else:
    print("Value is 20")
相关问题