2016-05-22 13 views
-4

私はログインメニューを作ろうとしています。変更可能なユーザー/パスシステムを作成しました。しかし、私はループから抜け出し、ユーザー名/パスワードをもう一度入力してもらいたいのですか?ここでPython - whileループを抜け出すには?

ソースコードです:

print ("Welcome, please login.") 

username = input("Please set a username") 
password = input("Please set a password") 

print ("please can you login") 
username_input = input("What is your username?") 
password_input = input ("What is your password?") 

if username_input == username and password_input == password: 
    while 1==1: 
     print ("1. Change username") 
     print ("2. Change password") 
     print ("3. Go back to login menu") 
     print ("4. Exit") 
     option = int(input("Please select an option, 1/2/3/4?")) 
     if option == 1: 
      username = input("Enter a new username") 
      print ("You username is now",username) 

     elif option == 2: 
      password = input("Enter a new password") 
      print ("Your password is now",password) 
     elif option == 3: 
      #Help 
     elif option == 4: 

      quit() 
+5

'break'を。 – miradulo

+0

これは非常に大きなくぼみです... –

+0

壊れていませんか?ただプログラムを終了します。 – HazardGames

答えて

0

あなたはループから抜け出すにしたい、それゆえ

break 

あなたがしたい正確に何をもう少し明確にあなたのanswer.Canです行う?

+0

ユーザーにパスとユーザーを再度尋ねるようにしますが、わかりません。 – HazardGames

+1

@HazardGamesその後、ユーザー名/パスワード入力をループに移動します。 –

+0

@HazardGames、それはあなたがしたいことがはっきりしていません。ユーザーが選択肢3のために行くと、彼は再び彼がユーザー名を入力しなければならないメインメニューであるパスワード? –

0

あなたはまだこの答えが必要な場合:そこのうち

Value = 2 
While value == 2 
print ("1. Change username") 
print ("2. Change password") 
print ("3. Go back to login menu") 
print ("4. Exit") 
option = int(input("Please select an option, 1/2/3/4?")) 
if option == 1: 
    username = input("Enter a new username") 
    print ("You username is now",username) 
    Value = 1 
elif option == 2: 
    password = input("Enter a new password") 
    print ("Your password is now",password) 
    Value = 1 
elif option == 3: 
    Pass 
elif option == 4: 

    quit() 
関連する問題