记录#
- 今天没有知识点学习,是代码练习。
- 今天要写一个日记程序:
- 为程序设置密码,密码正确才能访问
- 访问之后可以添加 / 查看日记
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()