記錄#
- 今天沒有知識點學習,是程式碼練習。
- 今天要寫一個日記程式:
- 為程式設置密碼,密碼正確才能訪問
- 訪問之後可以添加 / 查看日記
CODE#
from replit import db
import os, datetime
correctPassword = "1"
def add(t):
db[timestamp] = t
def view():
journal = db.keys()
show = "n"
for key in journal:
if show.lower() == "n":
print(f"{key}: {db[key]}")
elif show.lower() == "e":
break
show = input("Next or Exit? > ")
passwordEntered = input("Password? > ")
if passwordEntered != correctPassword:
exit()
else:
while True:
os.system("clear")
menu = input("Welcome\n1: Add\n2: View\n")
if menu == "1":
timestamp = datetime.datetime.now()
print(timestamp)
add(input("> "))
elif menu == "2":
view()