importoslogin_status =
defget_userdic():
user_dic =dict()
with open(
'user.txt
', '
r', encoding='
utf-8
') as f1:
for line in
f1: user_dic.update()
return
user_dic
defregister():
user_dic =get_userdic()
count =0
while count < 3:
new_name = input('
請輸入新使用者名稱》
').strip()
new_password = input('
請輸入新密碼》
').strip()
if new_name not
inuser_dic:
ifnew_name.isalnum():
if 6 < len(new_password) < 14:
with open(
'user.txt
', '
a', encoding='
utf-8
') as f1:
f1.write(f
'|\n')
print('
新增成功')
break
else
:
print('
密碼長度要在6~14個字元之間')
count += 1
else
:
print('
使用者名稱只能含有字母或者數字不能含有特殊字元')
count += 1
else
:
print('
使用者名稱已存在')
count += 1
defremove_user():
while 1:
remover = input('
請輸入要登出的賬號(q退出):
').strip()
user_dic =get_userdic()
if remover in
user_dic:
pw = input('
請輸入密碼:
').strip()
if pw ==user_dic[remover]:
user_dic.pop(remover)
with open(
'new_user.txt
', 'w'
) as f1:
for u, p in
user_dic.items():
f1.write(f'|
')os.remove(
'user.txt')
os.rename(
'new_user.txt
', '
user.txt')
elif remover.upper() == 'q'
:
break
else
:
print('
賬號不存在')
deflogin():
user_dic =get_userdic()
count =0
while count < 3:
username = input('
請輸入使用者名稱(q退出):
').strip()
if username.upper() == "q"
:
break
password = input('
請輸入密碼:
').strip()
if username in user_dic and user_dic[username] ==password:
login_status[
'use
'] =username
login_status[
'status
'] =true
break
else
:
print('
賬號密碼錯誤,重新輸入')
count += 1
defauth(f):
def inner(*args, **kwargs):
if login_status['
status']:
ret = f(*args, **kwargs)
return
ret
else
: login()
ret = f(*args, **kwargs)
return
ret
return
inner
@auth
defarticle():
while 1:
print('')
enter = input('
>>>(q返回)')
if enter.upper() == 'q'
:
break
@auth
defphoto():
while 1:
print('
歡迎進入**頁面')
enter = input('
>>>(q返回)')
if enter.upper() == 'q'
:
break
@auth
deffile():
while 1:
print('
歡迎進入檔案頁面')
enter = input('
>>>(q返回)')
if enter.upper() == 'q'
:
break
dic_home =
while 1:
for key in
dic_home:
(key)
user_choose = (input('
>>>'))
for key in
dic_home:
if user_choose ==key[0]:
dic_home.get(key)()
Python基礎刻意練習 Day17 模組
day1 變數 運算子與資料型別 day2 條件與迴圈 day3 4 列表與元組 day5 字串與序列 day6 7 函式與lambda表示式 day8 字典與集合 day9 10 檔案與檔案系統 day11 異常處理 day12 else 與 with 語句 day13 14 類與物件 day15...
python學習day17 遞迴函式
遞迴函式 def age n if n 4 return 40 elif n 0 and n 4 return age n 1 2 print age 1 46 只要寫遞迴函式,必須要有結束條件。二分法查詢 l 2,3,5,10,15,16,18,22,26,30,32,35,41,42,43,55...
Python 常用內建模組 Day17
養成乙個好的習慣只需要堅持21天,day17 datetime python中的datetime模組可以獲取當前日期和時間。from datetime import datetime now datetime.now 獲當前datetime print now print type now 2020...