Truel=""
count = 0
finle_touch=False #true after it find the first 3 upperletter
# check if there is 1 lower letter after three upper letter
def one_lower(i):
count=0
if i == i.lower:
finle_touch=True
Truel=i
# check for 3 upper letter
def three_upper(s):
for i in s:
if count == 3:
if finle_touch==True:
break
else:
one_lower(i)
elif i == i.upper:
count +=1
print(count) #for debug
else:
count ==0
finle_touch=False
stuff="dsfsfFSfsssfSFSFFSsfssSSsSSSS......."
three_upper(stuff)
print(Truel)
所以我有很多关于“东西”的字符串,我喜欢找到被 3 个大写字母包围的 1 个小写字母。
但是当我运行这段代码时,我得到:
Traceback (most recent call last):
File "C:\Python33\mypy\code.py", line 1294, in <module>
three_upper(stuff)
File "C:\Python33\mypy\code.py", line 1280, in three_upper
if count == 3:
UnboundLocalError: local variable 'count' referenced before assignment
我不明白为什么。