Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
622 views
in Technique[技术] by (71.8m points)

How to loop back to the beginning of the code on Python 3.7

After I type 5 usernames, it stops itself. How can I prevent that.

username = ['admin','bill','kevin','mike','nick']

for user in username:
 name = input("Please enter a username: ")
 if name == 'admin':
    print("Hello "+ name.title() + " ,would you like to see a status report?")
 else:
  if name in username:
   print("Hello " + name.title() + " thank you for logging in!")
  else:
      if name not in username:
          print("Who are you " + name.title() + " ? ")
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
username = ['admin','bill','Kevin','mike','nick']
while True :

    name =input("Please enter a username: ")
    if name=='admin' :
        print("Hello "+ name + " ,would you like to see a status report?")
        break
    elif name in username :
        print("Hello " + name.title() + " thank you for logging in!")
        break
    else:
        print("Who are you " + name.title() + " ? ")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...