我试图解决在checkio(house password)..我的代码如下的问题
def checkio(data):
if len(data)>9:
for i in data:
if str.isdigit(i)==True:
global counternumber
counternumber=counternumber+1
if str.isupper(i)==True:
global counterupper
counterupper=counterupper+1
if str.islower(i)==True:
global counterlower
counterlower=counterlower+1
if (counternumber>1 & counterupper>1 & counterlower>1):
return True
else:
return False
尝试实现以下错误时会弹出此功能
NameError:全局名称“ counterupper”未定义
在声明为全局变量之前,错误将弹出
UnboundLocalError: local variable 'counterupper' referenced before assignment,
这些错误是什么意思,以及如何解决?
请清楚地解释一下,因为我是编程新手。
您可以简短地写:
def checkio(data):
return (len(data) > 9 and
any(ch.isdigit() for ch in data) and
any(ch.isupper() for ch in data) and
any(ch.islower() for ch in data))
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句