|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
[python_code]import pickle
if input("是否初始化?(是)") == "是":
with open("history.txt","wb") as f:
pickle.dump([],f)
print("好了")
lst = []
while True:
expr = input(">>>")
if expr == "":
print("Bye!")
break
elif expr == "history":
with open("history.txt","rb") as f:
print('\n'.join(pickle.load(f)))
elif expr == "clear":
with open("history.txt","wb") as f:
pickle.dump([],f)
lst = []
print("已清空")
else:
try:
with open("history.txt","rb") as f:
lst = pickle.load(f)
print(eval(expr))
with open("history.txt","wb") as f:
lst.append(str(expr)+"="+str(eval(expr)))
pickle.dump(lst,f)
except ZeroDivisionError:
print("NaN")
except:
print("Error")[/code] |
|