import json
defget_store_number(filename):try:withopen(filename)as f:
number = json.load(f)except FileNotFoundError:returnNoneelse:return number
defget_number(filename):
number =input('What is your favorite number? ')withopen(filename,'w')as f:
json.dump(number,f)return number
defshow_number(filename):
number = get_store_number(filename)if number:print("I know your favorite number! It's "+number)else:
number = get_number(filename)
filename ='E:\\e.txt'
show_number(filename)
10-12 记住喜欢的数字:将练习10-11中的两个程序合而为一。如果存储了用户喜欢的数字,就向用户显示它,否则提示用户输入他喜欢的数字并将其存储到文件中。运行这个程序两次,看看它是否像预期的那样工作。import jsondef get_store_number(filename): try: with open(filename) as f: number = json.load(f) except FileNotFoundError: