【发布时间】:2017-06-27 21:39:44
【问题描述】:
我这里有一个代码,它使用函数来绘制输出。我不断收到“提示”未定义,但它不是已经在函数过滤器中说明了吗? [在此处输入图片说明][1]
def menu():
print ("[1] Compute Area of a Circle")
print ("[2] Compute Perimeter of a Rectangle")
print ("[3] Compute Volume of a Cone")
print ("[4] Compute Slope of a Straight Line")
print ("[5] Exit")
#Determining the input of the user
choice = filterer("Choose from the menu:")
#function for the filter
def filterer(prompt):
while True:
choice = float(input(prompt))
if choice > 5 or choice < 1:
print ("Must input integer between 1 and 5. Input again")
elif choice.is_integer == False:
print ("Must put an integer. Input again.")
else:
return prompt
filterer(choice)
【问题讨论】:
-
prompt在函数定义内定义,但不在函数定义外;即,它没有为filterer(prompt)行定义 -
在最后一行调用
filterer(prompt)时,prompt的值是多少?你还没有在任何地方定义它。 -
但不是使用“过滤器(提示)”的方式来调用函数值吗?我需要这个值,因为它将用于其他功能。
-
我不是在“else: return prompt”这行定义了吗?
-
我应该使用其他词而不是提示符吗?
标签: python python-3.x function iteration nameerror