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('數據不符合要求,請重新輸入整數:'))