知識點使用:1.格式化輸出的兩種方法---% .formatespa
2.while循環的使用,及跳出循環的兩種方法---break(跳出循環體)、continue(結束本次循環,繼續下次循環)code
3.if條件語句的使用orm
""" 功能:模擬用戶登陸,(3次重試機會,登陸成功展現登陸帳號密碼) 做者:諸葛 日期:29/06/2019 """ i = 3 username = 'zzl' password = '123456' #思路一:先驗證帳號,再驗證密碼 # while i > 0: # i -= 1 # name = input('請輸入用戶名:') # if name == username: # word = input('請輸入密碼:') # if word == password: # print('''恭喜您登錄成功! # -------帳號密碼信息------- # 用戶名:%s # 密碼:%s # ''' % (username, password)) # break # else: # print('''密碼輸入錯誤,請從新輸入! # ------剩餘嘗試次數{}次------'''.format(i)) # continue # # else: # print('用戶名不存在,請從新輸入!') # print('------剩餘嘗試次數{}次------'.format(i)) # continue # # else: # print('嘗試次數過多,請稍後重試!') #思路二:一次性驗證帳號密碼 while i > 0: i -= 1 name = input('請輸入用戶名:') word = input('請輸入密碼:') if name == username and word == password: print('恭喜您登錄成功!') print('''------登陸帳號信息------ 用戶名:%s 密碼:%s''' % (username,password)) break else: print('''對不起,帳號或密碼錯誤,請從新輸入! ------剩餘嘗試次數:{}------'''.format(i)) else: print('嘗試次數過多,請稍後重試!')