我有一個奇怪的問題,我不知道爲什麼會發生這種情況。我覺得很難解釋,但在這裏。我的程序工作正常,檢查長度,甚至力量。我的問題是,如果輸入以任何方式第一次失敗,然後重新輸入,並且是正確的長度和強度,它將重新要求密碼輸入。我想這是因爲最後一個像passwordbegin()
,但如果我刪除它,程序顯然不會運行。任何人都可以給我一個提示或向我解釋爲什麼會發生這種情況?提前致謝!程序循環如果第二次遇到強密碼
def passwordbegin():
Upper = 0
Lower = 0
Number = 0
pass_check = True
while pass_check is True:
passw = raw_input("Please enter your password. It must be between 6 and 12 characters long and contain atleast capital letter, lowercase letter and number.")
if len(passw) < 6:
print("Your password is too short, it must be at least 6 characters long")
elif len(passw) > 12:
print("Your password is too long, it must be no more than 12 characters long")
else:
print("Your password is the correct length.")
pass_check = False
if pass_check is False:
for char in passw:
if char.isupper():
Upper =+ 1
if char.islower():
Lower =+ 1
if char.isdigit():
Number =+ 1
Password_Strength = Number + Lower + Upper
if Password_Strength == 1:
print("Your password is weak, trying adding Numbers or Upper and Lowercase Letters")
raw_input("Press enter to restart the program")
while True:
passwordbegin()
if Password_Strength == 2:
print("Your password is medium strength, try adding Upper or Lowercase Letters and Numbers")
raw_input("Press enter to restart the program")
while True:
passwordbegin()
elif Password_Strength == 3:
print("Your password is strong and secure, thank you for entering!")
passwordbegin()
請解釋讓'passwordbegin'從一個嵌套循環內調用自己的原因,其中最內層的循環被明確地寫成無限循環。 – 2014-10-18 18:59:44
對不起,我不是最好的Python,我只是一個初學者。我已經這樣做了,所以如果Password_Strength == 1,然後按Enter鍵重新啓動功能 – user3411623 2014-10-18 19:06:24