用python写程序,用户名为:1密码为:123456让程序一直执行,直到输正确,显示‘欢迎回来’
发布网友
发布时间:2022-04-18 07:55
我来回答
共4个回答
热心网友
时间:2022-04-18 09:24
name=input('请输入用户名:')
while True:
#name=input('请输入用户名:')
if name=='1':
while True:
try:
powerword=eval(input('请输入密码:'))
if powerword==123456:
name=100
break
else:
print('密码不正确,请重新输入:')
except:
print('密码不正确,请重新输入:')
elif name==100:
break
else:
print('用户名不正确,请重新输入:')
name=input('请输入用户名:')
print('欢迎回来')
热心网友
时间:2022-04-18 10:42
#!python3
userdict = {'1':'123456'} #用户字典
trynum = 0
while True:
usern = input("用户名:")
userk = input("密码:")
realk = userdict.get(usern)
if realk:
if userk == realk:
print('\n>>>欢迎回来')
break
else:
print("\n>>>用户不存在,是否注册\ny:是\nn:否")
ans = input("选择:")
if ans == "y":
userdict[usern] = userk
trynum += 1
print('\n>>>重新登录(%d)'%trynum)
热心网友
时间:2022-04-18 12:17
username = '1'
password = '123456'
while 1:
u = input("Please input your username:")
p = input("Please input your password:")
if u == username and p == password:
print("Welcome back")
break
else:
print("Your inputing is invalid")
热心网友
时间:2022-04-18 14:08
USENAME = '1'
PASSWORD = 123456
while True:
get_name = input('Please enter your name:')
get_pwd = input('Enter your password:')
if get_name == USENAME and int(get_pwd) == PASSWORD:
print('Welcome Back!')
break