我正在尝试将 isdigit() 添加到程序中,以便我可以验证用户输入的内容是否有效。这就是我到目前为止所拥有的。但是当我运行它并输入一个字符时,说“f”。它崩溃并给我将在代码下方发布的错误。有任何想法吗?
def mirrorHorizontal(source):
userMirrorPoint = requestString("Enter a mirror point from 0 to halfway through the pitcure.") #asks user for an input
while (int(userMirrorPoint) < 0 or int(userMirrorPoint) > (int(getHeight(source) - 1)//2)) or not(userMirrorPoint.isdigit()):
userMirrorPoint = requestString("Enter a mirror point from 0 to halfway through the pitcure.")
height = getHeight(source)
mirrorPoint = int(userMirrorPoint)
for x in range(0, getWidth(source)):
for y in range(0, mirrorPoint):
topPixel = getPixel(source, x, y)
bottomPixel = getPixel(source, x, height-y-1)
color = getColor(topPixel)
setColor(bottomPixel, color)
错误是: f 不适当的参数值(类型正确)。尝试将参数传递给函数时发生错误。请检查 /Volumes/FLASHDRIVE2/College/Spring 16'/Programs - CPS 201/PA5Sikorski.py 的第 182 行