私は、文字列が有効なパスワードであるかどうかをチェックするパスワードチェッカーの作業中です。私は少なくとも8文字があるかどうかを確認しなければならず、文字と数字だけで構成されなければならず、最後の2文字は数字でなければなりません。str.isdigit()がPythonで動作していないようです
これまでのところ、password.isdigit()
以外はすべて動作しているようです。パスワードが有効になることがありますが、時にはそうではありません。助言がありますか?
# Gets the users password
password = input('Enter a string for password: ')
# Splices the last two characters of the password
lastTwo = password[-2:]
# Checks the password if it is less than 8 characters
while len(password) < 8:
print('The password you entered is too short.')
print()
password = input('Enter a string for password: ')
# Checks the password if it is composed of letters and numbers
while password.isalnum() == False:
print('Your password has special characters not allowed.')
print()
password = input('Enter a string for password: ')
# Checks the spice to verify they are digits
while lastTwo.isdigit() == False:
print('Your last two characters of your password must be digits.')
print()
password = input('Enter a string for password: ')
print('Your password is valid.')
ないいくつかの入力がどのようなものですが期待どおりに行動する? –
"何か提案" - 実際の問題を探します。 *あなたの*コードおよび/またはあなたの理解の中で。 –
最後の2文字の最後のループの直前にパスワードをスプライスする必要があります。さもなければ、それは前のパスワードの最後の2文字を含むでしょう – kuro