知識點使用:1.格式化輸出的兩種方法---% .formate
2.while循環的使用,及跳出循環的兩種方法---break(跳出循環體)、continue(結束本次循環,繼續下次循環)
3.if條件語句的使用
""" 功能:模擬用戶登錄,(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('嘗試次數過多,請稍后重試!')