2015-04-03 179 views
-1

我试图解决在checkio(房子密码)的问题 ..my代码如下什么是

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, 

这些错误意味着什么以及如何解决它们?

请解释清楚,因为我是新来的编程..

+0

你并没有真正搜索,是吗? http://stackoverflow.com/search?q=local+variable+referenced+before+assignment – 2015-04-03 12:36:22

回答

1

可以在短写:

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))