输入5个用户名后,它会自行停止。我该如何预防。
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() + " ? ")
答案 0 :(得分:0)
您可以使用无限循环。这是一个例子。 “ while True”永远有效。
username = ['admin','bill','kevin','mike','nick']
while True:
name = input("What's your nickname?")
if(name in username):
print("Hello " + name + "! Thank you for logging in!")
答案 1 :(得分:0)
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() + " ? ")
答案 2 :(得分:0)
我想你可能看起来像这样:
username = ['admin','bill','Kevin','mike','nick']
while True:
while True :
name = input("Please enter a username: ")
if name=='admin' :
print("Hello "+ name + " ,would you like to see a status report?")
answer = input()
if answer == 'yes':
print('report')
break;
if name in username :
print("Hello " + name.title() + " thank you for logging in!")
break;
else:
print("Who are you " + name.title() + " ? ")
break;
在另一个循环中使用一会儿True循环,这样每当第二个循环中断时,就会循环回到第一个循环。
希望获得帮助。