Dario Ongsono Dario Ongsono - 2 months ago 31
Python Question

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)

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

elif current > 1:


Could somebody please help me what is wrong with my elif statement? Thanks in advance!

Answer

here is your issue: return 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. Performed debug and checks out:

Connected to pydev debugger (build 162.1967.10) Process finished with exit code 0

correct will be: makeEmptyPicture(numTilesI), numTilesI, color