2

ユーザーが自分のアカウントにログインして設定したコマンドを使用できるログインシステムを作成しようとしていますが、ユーザーがログインシステムに登録できるように、いくつかの追加入力を追加したかったのです。設定したコマンドを使用します。ユーザーが行った入力を毎回別の変数に永続的に保存して、ユーザーがコードを再起動したときにシステムにログインでき、再度登録する必要がないようにしたいと考えていました。

これまでに作成したコードは次のとおりです。

print ("Welcome!")
print ("Would you like to register")
loop = True

while (loop == True):
    username = input ("username: ")
    password = input ("password: ")
    print ("register here if you don't have an account")
    username1 = input ("name: ")
    print ("this is what you use to login to the system")
    username2 = input ("username: ")
    username3 = input ("password: ")

    if (username == "rohit" and password == "rodude") :
        print ("hello and welcome " + username or )
        loop = False
        loop1 = True

    else:
        print ("invalid username and password")

    while(loop1 == True):

        command = str(input(username + "{} > >"))
        if(command.lower() == "exit"):
            loop1=False

        elif(command.lower() == "hi"):
            print("Hi " + username + "!")

        else:
            print ("'" + command + "' is an invalid command!")
4

2 に答える 2

1

やあ、あなたのやり方は複雑すぎて、あなたにできることはこれだけです

    name = open("usernames.txt", "w") #opens file usernames.txt and gets ready to write to it
file = input("please type some text: ") #asks user for text in code

name.write(file) #writes contents in file to usernames.txt
name.close() #closes file
open1 = open("usernames.txt", "r") #opens file to read it
print (open1.read()) #prints whatever is in the text file
于 2015-10-20T19:13:55.890 に答える
0

ローカル ストレージに変数を使用することはできません。プログラムの実行間で情報を保持したい場合は、それを永続的な場所 (通常はディスク ファイルまたはデータベース) に格納する必要があります。これを簡単にするために利用できるモジュールはたくさんあります。Pickle (klashxx の応答で指摘されているように) は、単純なシナリオには優れたモジュールです。

于 2014-07-02T18:38:19.540 に答える