基础需求:
- 让用户输入用户名密码
- 认证成功后显示欢迎信息
- 输错三次后退出程序
count=1 PS=0 name=input("Please input your name:") password=input("Please input your password:") while count<=2 and PS==0: if name=="root" and password=="1234": PS=1 print("Welcome!") elif count==2: name=input("Lasttime!Please enter :") password=input("Please input your password:") count+=1 else: name=input("Wrong! Please enter again:") password=input("Please input your password:") count+=1 if count==3 and PS==0: print("End!!")
可以支持多个用户登录
count=1 #登录次数计数位 PS=0 #登录成功标志位 name_list=['root','hao','quan'] ps_list=['123456','111','666'] name=input("Please input your name:") password=input("Please input your password:") while count<=3 and PS==0: if name in name_list: i=name_list.index(name) if (name in name_list) and (password==ps_list[i]): PS=1 print("Welcome!") elif count<2 : name=input("Wrong! Please enter again:") password=input("Please input your password:") count+=1 continue else : name=input("Lasttime!Please enter :") password=input("Please input your password:") count+=1 continue elif count==2 and PS==0: name=input("Lasttime!Please enter :") password=input("Please input your password:") count+=1 else: name=input("Wrong! Please enter again:") password=input("Please input your password:") count+=1 if count==3 and PS==0: print("End!!")