Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
630 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 Reply

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() + " ? ")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...