简体   繁体   English

Python:如果 elif

[英]Python: If elif

i am trying to create a function that creates an empty coloured picture given the numbers of tiles from createSquareTile(numTiles, prefix)我正在尝试创建一个函数,根据 createSquareTile(numTiles, prefix) 中的图块数量创建一个空的彩色图片

def createSquareTile(numTiles, prefix):
  current = 1
  if current == 1:
    numTiles = requestNumber("Please input a positive number")
    numTilesI = int(numTiles)

    while (numTilesI < 0):
      showError("Your input number" + str(numTiles)+ "is not valid. Do it       again!")
      numTiles = requestNumber("Please input a positive number")

    if (numTilesI > 0):
    current = current + 1
    color = pickAColor()
    return makeEmptyPicture(numTilesI), numTilesI), color)

  elif current > 1:
    previousChoice = requestString("Same size as pervious tile? (Y/N)")

    while (previous != "N") and (previous != "Y"):
      showError("Your input character" + previousChoice + "is not valid. Do it again!")
      previousChoice = requestString("Same size as previous tile? (Y/N)")

    if (previousChoice == "Y"):
      color = pickAColor()
      return makeEmptyPicture(numTilesI, numTilesI, color)
      current = current + 1


    elif (previousChoice == "N"):
      numTilesN = requestNumber("Please input a positive number")
      numTIlesNI = int(numTilesN)
      colorN = pickAColor()
      return makeEmptyPicture(numTilesNI, numTilesNI, colorN)
      current = current + 1

According to python, there was a spacing error at根据python,在

elif current > 1:

Could somebody please help me what is wrong with my elif statement?有人可以帮助我我的 elif 语句有什么问题吗? Thanks in advance!提前致谢!

Possible reasons:可能的原因:

  • The line above it has wrong white spaces.它上面的行有错误的空格。
  • You mixed tab with space .您将tabspace混合在一起。
  • You have some hidden characters by accident.你偶然有一些隐藏的角色。

Why not first try to remove the white line above it?为什么不首先尝试删除它上面的白线? If all possibilities won't work, please make a comment.如果所有可能性都不起作用,请发表评论。

here is your issue: return makeEmptyPicture(numTilesI), numTilesI), color)这是你的问题:返回 makeEmptyPicture(numTilesI), numTilesI), color)

you should remove the ) from numTilesI), color) and should work because actually your program stops at this line and not moving forward.你应该删除)numTilesI), color) ,并应工作,因为实际上你的程序停止在这条线,而不是前进。 Performed debug and checks out:执行调试并检查:

Connected to pydev debugger (build 162.1967.10) Process finished with exit code 0连接到 pydev 调试器 (build 162.1967.10) 进程完成,退出代码为 0

correct will be: makeEmptyPicture(numTilesI), numTilesI, color正确的将是: makeEmptyPicture(numTilesI), numTilesI, color

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM