Python elif语句语法错误

时间:2017-04-11 10:21:56

标签: python-3.x

我是python编程的新手。我在elif声明中遇到问题。我无法找出语法错误。我的代码如下。

for num in range(1,31):  

       if (num%5 == 0) or (num%3 == 0):  

          if (num%3 == 0):
             print ("beep")
             elif (num%5 == 0):
                print ("boop")
             else:
                print ("beepboop")

       else:          

      print (num)

1 个答案:

答案 0 :(得分:2)

错误的缩进

for num in range(1, 31):
    if (num % 5 == 0) or (num % 3 == 0):
        if num % 3 == 0:
            print("beep")
        elif num % 5 == 0:
            print("boop")
        else:
            print("beepboop")
    else:
        print(num)