10月 092020
 
#定义密码列表并赋值给变量
password_list = ['*#*#', '12345']
#定义函数
def account_login():
    password = input('Password:') #用户输入赋值变量
    password_correct = password == password_list[-1] #使用列表索引取值进行布尔运算并赋值变量
    password_reset = password == password_list[0]
    if password_correct: #条件成立打印信息
        print('Login success!')
    elif password_reset: #反之,password_reset条件成立(即输入*#*#)
        new_password = input('Enter a new password:') #用户输入赋值变量
        password_list.append(new_password) #列表追加数据
        print('Your password has changed successfully!')
        account_login() #继续调用函数
    else: #反之,打印错误信息
        print('Wrong password or invalid input!')
        account_login()
#调用函数
account_login()
PS C:\Users\harveymei> & C:/Users/harveymei/AppData/Local/Programs/Python/Python39/python.exe c:/Users/harveymei/hello.py
Password:54321
Wrong password or invalid input!
Password:12345
Login success!
PS C:\Users\harveymei> & C:/Users/harveymei/AppData/Local/Programs/Python/Python39/python.exe c:/Users/harveymei/hello.py
Password:*#*#
Enter a new password:hahaha
Your password has changed successfully!
Password:hahaha
Login success!
PS C:\Users\harveymei>

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据