在邏輯運算子中找不到錯誤,可能有人可以給我一個提示如何放置 AND OR OR。
問題在于如果資料和資料和資料和(或或或)
在 () > 我需要接受代碼:包含大寫字母,那么大寫字母的數量必須是奇數至少有 4 個字母(與大小寫無關)所以這意味著:UPPER LOWER >= 4 或 UPPER >= 4 或 LOWER > = 4
輸出應該是:
checker_code("Dfgh#88$")
True
def checker_code(security_code):
data = {'upper':0, 'lower':0, 'spec':0, 'digit':0, 'sum':0}
spec_charact = ['!','@','#','$','%','^','&','*','(',')','?',',','.']
if len(security_code) < 8 or len(security_code) > 30:
return False
for i in security_code:
if any(i.isupper() for i in security_code):
data['upper'] = data['upper'] 1
if i.islower():
data['lower'] = data['lower'] 1
if i in spec_charact:
data['spec'] = data['spec'] 1
if i.isdigit():
data['digit'] = data['digit'] 1
if i.isdigit():
data['sum'] = data['sum'] int(i)
if(data['upper'] % 2 !=0 and data['spec'] >= 2 and data['digit'] >= 2 and data['sum'] % 2 == 0 and (data['upper'] data['lower'] >= 4 or data['upper'] >= 4 or case['lower'] >= 4)):
return True
else:
return False
uj5u.com熱心網友回復:
改變你的線路
if any(i.isupper() for i in security_code):
對此:
if i.isupper():
由于您已經for i in security_code在外部 for 回圈中進行了迭代,因此在您的第一個 if 陳述句中再次進行迭代是多余的。我認為您的代碼正在應用第一個字符是否在所有字母中都是大寫的,因此它認為您的 8 個字符的字串有 8 個大寫字符,因為“D”是大寫的
uj5u.com熱心網友回復:
您的測驗每次都在回圈中if any(i.isupper() for i in security_code):添加,data["upper"]因為您security_code在每次迭代時都檢查所有內容,并且由于它確實有一個大寫字母,因此它會添加到計數中。
相反,只需if i.issuper():檢查安全代碼的當前元素即可。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/367732.html
標籤:蟒蛇-3.x
上一篇:重組元組串列
下一篇:抓取html鏈接Python
