import json
def get_favorite_num():
filename = 'favoritenum.json'
try:
with open(filename) as f_obj1:
favorite_num = json.load(f_obj1)
except FileNotFoundError:
num = int(input('请输入你最喜欢的数字:'))
with open(filename, 'w') as f_obj:
json.dump(num, f_obj)
print('您输入的数字是:' +str(num))
else:
print('I konw your favorite number! It is ' + str(favorite_num) + '.')
get_favorite_num()