python中的IndentationError(pygame)

时间:2017-03-12 19:16:58

标签: python

if lead_x > randAppleX and lead_x < randAppleX + AppleThickness or lead_x + block_size > randAppleX and lead_x + block_size < randAppleX + AppleThickness:
#   print("x crossover")
   if lead_y > randAppleY and lead_y < randAppleY + AppleThickness:
#    print("x and y crossover")

   elif lead_y + block_size > randAppleY and lead_y + block_size < randAppleY + AppleThickness:

IndentationError: expected an indented block

有人看到错误吗?请帮忙:(

1 个答案:

答案 0 :(得分:0)

Python要求每个块至少包含一个语句,而注释不是语句。所以,这在语法上是错误的:

func autoScroll () {
    let co = collectionView.contentOffset.x
    let no = co + 1

    UIView.animate(withDuration: 0.01, delay: 0, options: .curveEaseInOut, animations: { [weak self]() -> Void in
        self?.collectionView.contentOffset = CGPoint(x: no, y: 0)
    }) { [weak self](finished) -> Void in
        self?.autoScroll()
    }
}

为此,请在需要时使用no-op pass statement,例如注释掉单行块:

if lead_y > randAppleY and lead_y < randAppleY + AppleThickness:
    #    print("x and y crossover")