-1
私は学校のプロジェクト(変数名について説明しています)にこのコードを持っていますが、forループの最下位に行くとリストのインデックスが範囲外です。パスワードを尋ねる前に、ユーザー名を入力してチェックすることになっています。私は何が間違っているのか理解しようとしましたが、何もできません。forループからのIndexErrorを理解しない
def passwordSystem():
#TASK ONE
username_array = []
password_array = []
for i in range (1, 30):
username_to_be_entered = str(input("Enter a username"))
acceptable_password = False
while not acceptable_password:
password_to_be_entered = str(input("Enter a password between 6 and 12 characters"))
if len(password_to_be_entered) > 12 or len(password_to_be_entered) < 6:
print ("Your password was not between 6 and 12 characters")
else:
acceptable_password = True
print ("Password accepted")
print ("Your username is:" ,username_to_be_entered)
print ("Your password is:" ,password_to_be_entered)
#TASK TWO
username_accepted = False
while not username_accepted:
username_to_be_checked = str(input("Please enter your username"))
for i in range (1, 30):
if username_array[i] == username_to_be_checked:
print ("Username accepted")
username_accepted = True
完全なエラーメッセージを投稿できますか? –
自分で配列全体を反復処理する必要はありません。 'in'を使うだけです。 – wpercy
usernameの配列は永遠に空のままなので、' username_array [i] 'をチェックしようとすると、配列の終わりを常に過ぎます。 – turbulencetoo