phone_letters =[" ", "1", "ABC","DEF","GHI","JKL","MNO","PQRS","TUV","WXYZ","*","0","#" ]
key = 0
string = input("Enter a Letter: ",)
while key < 10 :
if string in phone_letters[key]:
print(key)
return key
else:
key = key+1
return "not found"
我遇到错误'return' outside function
;我检查了缩进,但错误仍然存在。
答案 0 :(得分:1)
return
可能仅在语法上嵌套在函数定义中
来源:https://docs.python.org/3/reference/simple_stmts.html#the-return-statement
您的返回未嵌套在函数内。因此,错误。
如果要显示文本,可以使用print("not found")
。