关于循环的作业:登陆程序

要求写一段登陆程序:

1、输入用户名和密码

2、认证成功之后提示登陆成功

3、如果用户名和密码输错3次,就强制退出

 

#!/usr/bin/nev python
#-*-coding:utf-8 -*-
#Author :show530

username = 'hongtao'
password = '123456'

for i in range(3):
    input_user = str(input("Please enter your name:  "))
    input_pass = str(input("Please enter your password:  "))
    if input_user == username and input_pass == password:
        print("\033[7;37;42m==============================")
        print("Welcome,Login succeeded!!")
        print("==============================\033[7;37;42m")
        print('\033[0m')
        break
    else:
        print("\033[7;31m==============================")
        print(" Incorrect username or password!!")
        print("==============================")
        print("You have "+str(2-i)+ " more chances!!")
        print("==============================\033[1;37;40m")
        print('\033[0m')
else:
    print("\033[7;31m==============================")
    print("Too many incorrect username or password for account !!")
    print("Prohibit further operations!")
    print("==============================\033[1;31;40m")
    print('\033[0m')

 

posted @ 2020-02-28 17:19  洪韬  阅读(104)  评论(0编辑  收藏  举报