10 月 092020
 
#条件控制
#如果……条件是成立的,就做……,反之,就做……
#定义一个函数
def account_login():
    password = input('Password:') #使用input获得用户输入字符串并存储在变量中
    if password == '12345': #条件
        print('Login success!')
    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:12345
Login success!
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>

 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)