第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Python計(jì)算賬戶金額的問(wèn)題

Python計(jì)算賬戶金額的問(wèn)題

倚天杖 2023-09-05 15:49:36
我正在使用 requests 庫(kù)用 Python 編寫我的機(jī)器人。該機(jī)器人的本質(zhì)是計(jì)算賬戶上所有物品的總金額。一切正常,但金額沒有按照我的需要計(jì)算。API 密鑰作為字典:apikeys = {'account1' : [id1, apikey1], 'account2' : [id2, apikey2], 'account3' : [id3, apikey3]}我的代碼:total = 0for key, value in apikeys.items():    url = request.get('https://market.com/api/items?=key={api}'.format(api=value[1])).json()['items']    for i in url:        total += i['price']    JSON 答案:ACCOUNT1 = {'items': [           'item 1': {                     'status': '1',                     'price': '10'                     },           'item 2': {                     'status': '1',                     'price': '20'                     },           'item 3': {                     'status': '1',                     'price': '30'                     },  ACCOUNT2 = {'items': [           'item 1': {                     'status': '1',                     'price': '40'                     },           'item 2': {                     'status': '1',                     'price': '50'                     },           'item 3': {                     'status': '1',                     'price': '60'                     },ACCOUNT3 = {'items': [           'item 1': {                     'status': '1',                     'price': '70'                     },           'item 2': {                     'status': '1',                     'price': '80'                     },           'item 3': {                     'status': '1',                     'price': '90'                     },            我的機(jī)器人從我獲得的所有帳戶中收集所有物品, 總計(jì) = 450 ( 10 + 20 + 30 + 40 + 50 + 60 + 70 + 80 + 90 = 450 )total = 450但我需要將每個(gè)帳戶的金額分開:I need:ACCOUNT1 = 10 + 20 + 30 = 60ACCOUNT2 = 40 + 50 + 60 = 150ACCOUNT3 = 70 + 80 + 90 = 40
查看完整描述

1 回答

?
鳳凰求蠱

TA貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超4個(gè)贊

account_total = {}

for key, value in apikeys.items():

    url = request.get('https://market.com/api/items?key={api}'.format(api=value[1])).json()['items']

    total = 0

    for i in url:

        total += i['price']

    account_total[key] = total


查看完整回答
反對(duì) 回復(fù) 2023-09-05
  • 1 回答
  • 0 關(guān)注
  • 158 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)