python初體驗

金角大王 的課程確實不錯。spa

從第一節課做業寫起。直接看吧。code

 

 

 1 import sys
 2 user_name = "alx"
 3 password = 123456
 4 import time
 5 
 6 import os
 7 if os.access("lock.txt", os.F_OK):
 8     with open('lock.txt') as read_file:
 9         old_time = read_file.read().strip()
10         old_time = float(old_time)
11 
12     new_time = time.time()
13     time_difference = new_time - old_time
14 
15     if time_difference <400:
16         print ("系統鎖定中,請5分鐘後再試!")
17         sys.exit(0)
18 
19 
20 for i in range(3):
21     guest_name = input("plesea you name")
22     if guest_name == user_name:
23         print ("姓名匹配成功!")
24         guest_password = int(input("plesea you password"))
25         if guest_password == password:
26             print ("恭喜登陸成功")
27             break
28         else:
29             print ("密碼輸入錯誤,請重試")
30     elif i == 2:
31         print("機會用完了!你是豬嗎")
32         time_save= open("lock.txt","w+")
33         time_save.write(str(time.time()))
34     else:
35         print("姓名未查詢到,請覈實!")
相關文章
相關標籤/搜索