python作業二

來源:互聯網
上載者:User

標籤:art   log   div   lock   鎖定   for   exit   rip   第一次用   

1.假設一年期利率為3.25%,計算一下需要過多少年,一萬元的一年定期存款連本帶利能翻番

money = 10000#錢interest = 0.0325#利率count = 0#次數while money < 20000:    count+=1    money+=money*interest    print("money",count,money)


2.基礎需求:讓使用者輸入使用者名稱密碼認證成功後顯示歡迎資訊輸錯三次後退出程式升級需求:可以支援多個使用者登入 (提示,通過列表存多個賬戶資訊)使用者3次認證失敗後,退出程式,再次啟動程式嘗試登入時,還是鎖定狀態(提示:需把使用者鎖定的狀態存到檔案裡)

user =[["alex",‘123‘],["shan",‘456‘]]count = 0pass_auth_flag = False #標誌位first_input_user = None#記住第一次使用者名稱is_same_user = True#用於判斷三次輸入的使用者名稱是否相等#從檔案f = open("lock_file","r")lockd_users = []for line in  f:    lockd_users.append(line.strip())#print("lockd user:",lockd_users)while count<3:    username = input("username:").strip()    password = input("password:").strip()    if username in lockd_users:        exit("使用者鎖定")    if not first_input_user:#如果沒值,代表第一次        first_input_user = username    if username != first_input_user:        is_same_user = False #多次輸入就不是同一個使用者名稱了    for _user  in user:        if _user[0] == username and _user[1] == password:            print("登入成功![%s]歡迎進入"%username)            pass_auth_flag = True#認證成功            break            #exit()    else:        print("使用者名稱或密碼錯誤!")    if pass_auth_flag is True:        break    count+=1else:    print("輸入次數過多")    if is_same_user is True:        f = open("lock_file","a")        f.write(username+"\n")        f.close()        print("此使用者已經鎖定!",username)

 



python作業二

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.