私はメニューシステムのいくつかのコードにいくつかの問題があります。私がこれまでにしてきたことは完了していないが、問題がある。それはaccount.leeman 'とうまく動作しますが、私は決して「管理者」に仕事をさせることはできず、常に最初にロールバックします。私はしばらくの間、コードを見てきましたが、なぜこれが、そしてなぜこれが続くのではないのか理解できません。Python 3のwhileループwhile
usernames=["m.leeman","administrator"]
passwords=["pA55w0rd","password"]
while True:
count=0
add_or_enter=input("Would you like to Enter a username or Add a new one?: ").lower()
if add_or_enter=="enter":
username=input("Please enter username: ")
while (count+1)!=(len(usernames)):
#problem somewhere here
if username==usernames[count]:
print("Username accepted")
password=input("Please enter password: ")
if password==passwords[count]:
print("Welcome "+str(username))
print("Continue here")
else:
print("Incorrect password")
else:
count+=1
if count==len(usernames):
print("User does not exit")
else:
()
#should run again after this
elif add_or_enter=="add":
new_user=input("Enter a new username: ")
if (new_user=="add") or (new_user==usernames[count]):
print("Username unavailiable")
else:
count=+1
if count==len(usernames)-1:
usernames.append(new_user)
new_password=input("Enter a password for this user: ")
passwords.append(new_password)
print("User "+new_user+" successfully created")
:それはまだ問題ではありませんよう、あなたがそれを改善するにはどのような方法を見ることができれば、私は
を教えてくださいが、コードの「追加」の部分は、だからこれは私が持っているもので、無視することができます
すべての返信は非常に役に立ちます。ありがとう。
を助け削除しますか? – roganjosh
仮に、 'while count!= len(usernames):'を実行するとどうなりますか? – Kevin
'raw_input'' username'と '" m.leeman \ n "'からのユーザ入力に隠れた改行があるかもしれないようですが、 ''どこかのどこかに ''どこかの問題 ' username.strip()==ユーザ名[count] .strip(): 'は文字列を消去し、改行を削除します。私はそれを試したときに働いた。 – davedwards