我正在嘗試創建一個密碼重置程序,其中包括計算所述密碼中有多少個小寫字母和大寫字母。如果密碼少於8個字母或不包含大寫或小寫,它拒絕了密碼,但該程序崩潰時,有數字,因爲它無法計算有多少數字有:如何統計變量中的數字
import time
print("Please create a new password")
password = input()
print("Re-enter your password")
password2 = input()
if password != password2:
print("Your Passwords Do Not Match")
time.sleep(2)
print("Please create a new password")
password = input()
print("Re-enter your password")
password2 = input()
valid = 0
lower = 0
upper = 0
for c in password:
if c.islower():
lower += 1
elif c.isupper():
upper += 1
else:
pass
char_count = upper + lower
if char_count >= 8:
valid += 1
if lower >= 1:
valid += 1
else:
print("Your Password Has No Lowercase Letters")
if upper >= 1:
valid += 1
else:
print("Your Password Has No Uppercase Letters")
else:
print("Your Password Doesn't Have 8 Characters")
if valid == 3:
print("Your Password Is Valid. Welcome")
else:
print("Your Password Is Invalid. Sorry")
time.sleep(2)
print("Please create a new password")
password = input()
print("Re-enter your password")
password2 = input()
編輯:謝謝你你的幫助,但我的計劃有效!多謝你們!