import json
new_datas = []
with open('./files/data.json', 'r', encoding='utf-8')as f:
for item in json.load(f)['data']:
new_data = {'name': item['name'],'text':item['text'],'love': item['love'],'comment': item['comment']}
new_datas.append(new_data)
with open('./files/new_data.json', 'w', encoding='utf-8')as f:
json.dump(new_datas, f)
统计data.json中comment数量超过1000的个数
count = 0
with open('./files/data.json', 'r', encoding='utf-8')as f:
for item in json.load(f)['data']:
if int(item['comment']) > 1000:
count += 1
print('统计data.json中comment数量超过1000的个数:%d'%(count))
import random
value = random.randint(1,100)
# print(value)
while True:
#
try:
number = int(input('请猜一个数字:'))
# number = int(input('请猜一个数字:'))
if number > value:
number = int(input('大了,请重新输入:'))
elif number < value:
number = int(input('小了,请重新输入:'))
else:
print('恭喜,猜测正确!')
break
# else:
# number = int(input('输入错误,请重新输入:'))
#
except:
number = int(input('数据不符合要求,请重新输入整数:'))