欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python文件操作模擬用戶登陸代碼實(shí)例

 更新時(shí)間:2020年06月09日 10:15:32   作者:碼出江湖  
這篇文章主要介紹了Python文件操作模擬用戶登陸代碼實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

題目要求

1、輸入用戶名和密碼后回車

2、密碼輸入錯(cuò)誤,給出提示,并選擇是否重新輸入

3、密碼輸入錯(cuò)誤三次后,用戶被鎖定,無法繼續(xù)登陸

構(gòu)思

1、用戶輸入賬號(hào)和密碼后,需要判斷賬號(hào)是否存在

2、判斷賬號(hào)是否被禁用(錯(cuò)誤次數(shù)大于三次)

3、判斷賬號(hào)密碼是否正確

4、不同的錯(cuò)誤給出不同的提示

5、每輸入錯(cuò)一次,文檔中的錯(cuò)誤次數(shù)需要更新

6、如果三次以內(nèi)用戶登陸成功,密碼原來的錯(cuò)誤次數(shù)被重置

題目完成步驟

1、文檔的編寫

考慮到數(shù)據(jù)的存儲(chǔ)問題,決定將賬號(hào)、密碼、錯(cuò)誤次數(shù)進(jìn)行分行存儲(chǔ),三行為一組用戶信息

2、代碼編寫

go = True
while go:
  # 用來判斷賬號(hào)是否存在
  no_existence_flag = True
  # 用來判斷是否輸入正確
  no_flag = True
  # 用來判斷是否已經(jīng)被封
  disable_flag = True
  # 用來判斷次數(shù)是否已經(jīng)超過限制
  account = input("account:")
  password = input("password:")
  # 判斷賬號(hào)是否存在(自己寫入已存在用戶的賬號(hào)密碼)
  file = open("C:/Users/Lenovo/Desktop/user.txt","r")
  # 用于拼接文本內(nèi)容
  file_data = ""
  while True:
    line = file.readline()
    if not line:
      break
    file_data += line
    line_content = line.strip()
    # 判斷是否存在賬號(hào)
    if account == line_content:
      no_existence_flag = False
      true_password = file.readline()
      file_data += true_password
      true_password_content = true_password.strip()
      disable_flag_line = file.readline()
      disable_flag_num = int(disable_flag_line.strip())
      # 判斷賬號(hào)是否被禁用
      if disable_flag_num != 3:
        print("It is not disable!",disable_flag_num)
        disable_flag = False
        # 判斷密碼是否正確
        if password == true_password_content:
          no_flag = False
          print("Welcome in this system,{account}!".format(account = account))
          go = False
          disable_flag_line = disable_flag_line.replace(str(disable_flag_num),str(0))
          file_data += disable_flag_line
        else:
          disable_flag_line = disable_flag_line.replace(str(disable_flag_num),str(disable_flag_num+1))
          file_data += disable_flag_line
      else:
        file_data += file.readline()
    else:
      file_data += file.readline()
      file_data += file.readline()
  file.close()
  # 賬號(hào)不存在的報(bào)錯(cuò)
  if no_existence_flag:
    print("This account is not existence!")
    print("Do you want to try it again......")
    flag = input("Please input you think:")
    if flag == "N":
      go = False
    continue
  # 賬號(hào)被禁用的報(bào)錯(cuò)
  if disable_flag:
    print("You account is disable,please go home by youself!")
    print("Do you want to try it again......")
    flag = input("Please input you think:")
    if flag == "N":
      go = False
    continue
  # 賬號(hào)密碼錯(cuò)誤的報(bào)錯(cuò)
  if no_flag:
    file = open("C:/Users/Lenovo/Desktop/user.txt","w")
    print(file_data)
    file.write(file_data)
    file.close()
    print("Your password is not right,please try it again!")
    print("Do you want to try it again......")
    flag = input("Please input you think:")
    if flag == "N":
      go = False
  # 重置輸入次數(shù)
  else:
    file = open("C:/Users/Lenovo/Desktop/user.txt","w")
    print(file_data)
    file.write(file_data)
    file.close()

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • python中defaultdict用法實(shí)例詳解

    python中defaultdict用法實(shí)例詳解

    python中的dict是一個(gè)重要的數(shù)據(jù)類型,知道如何使用這個(gè)數(shù)據(jù)類型很簡(jiǎn)單,但是這個(gè)類型使用過程中容易進(jìn)入一些誤區(qū),下面這篇文章主要給大家介紹了關(guān)于python中defaultdict用法的相關(guān)資料,需要的朋友可以參考下
    2022-09-09
  • 通過實(shí)例解析python subprocess模塊原理及用法

    通過實(shí)例解析python subprocess模塊原理及用法

    這篇文章主要介紹了通過實(shí)例解析python subprocess模塊原理及用法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-10-10
  • python等待10秒執(zhí)行下一命令的方法

    python等待10秒執(zhí)行下一命令的方法

    在本篇文章里小編給大家整理的是關(guān)于python等待10秒執(zhí)行下一命令的方法及實(shí)例,需要的朋友們可以參考下。
    2020-07-07
  • TensorFlow深度學(xué)習(xí)之實(shí)現(xiàn)合并與分割的示例代碼

    TensorFlow深度學(xué)習(xí)之實(shí)現(xiàn)合并與分割的示例代碼

    這篇文章主要為大家詳細(xì)介紹了TensorFlow中實(shí)現(xiàn)合并與分割的四位函數(shù)以及它們的用法,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以了解一下
    2023-07-07
  • python保存兩位小數(shù)的多種方法匯總

    python保存兩位小數(shù)的多種方法匯總

    很多小伙伴在學(xué)習(xí)python的時(shí)候可能會(huì)遇到對(duì)數(shù)據(jù)進(jìn)行格式化輸出的需求,其中最常見的需求為:保留幾位小數(shù),下面這篇文章主要給大家介紹了關(guān)于python保存兩位小數(shù)的多種方法,需要的朋友可以參考下
    2021-12-12
  • 詳解用 python-docx 創(chuàng)建浮動(dòng)圖片

    詳解用 python-docx 創(chuàng)建浮動(dòng)圖片

    這篇文章主要介紹了詳解用 python-docx 創(chuàng)建浮動(dòng)圖片,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-01-01
  • Python循環(huán)語句之break與continue的用法

    Python循環(huán)語句之break與continue的用法

    這篇文章主要介紹了Python循環(huán)語句之break與continue的用法,是Python入門學(xué)習(xí)中的基礎(chǔ)知識(shí),需要的朋友可以參考下
    2015-10-10
  • TensorFlow打印tensor值的實(shí)現(xiàn)方法

    TensorFlow打印tensor值的實(shí)現(xiàn)方法

    今天小編就為大家分享一篇TensorFlow打印tensor值的實(shí)現(xiàn)方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2018-07-07
  • python調(diào)用百度API實(shí)現(xiàn)人臉識(shí)別

    python調(diào)用百度API實(shí)現(xiàn)人臉識(shí)別

    這篇文章主要介紹了python調(diào)用百度API實(shí)現(xiàn)人臉識(shí)別,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-11-11
  • Python格式化輸出的具體實(shí)現(xiàn)

    Python格式化輸出的具體實(shí)現(xiàn)

    本文主要介紹了Python格式化輸出的具體實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-06-06

最新評(píng)論