亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

盡管只需要執行一部分代碼,但執行所有行的代碼

盡管只需要執行一部分代碼,但執行所有行的代碼

阿波羅的戰車 2023-12-05 15:46:51
所以它是這樣的,當我輸入一個查詢時,它被解析和兩個值并拉出這是日期和指示器,并最初獲得該日期的適當響應response = {'l_result': [{'deaths': 5, 'tested': 5,}]}if value('DATE'):     print("===================")     print("this is the response ")     print(response)     print("===================")if value('indicator'):mapped_indicator = values('indicator')[-1]   if mapped_indicator == 'Tested':      tested_list = [       {'total_tested': response.get('tested'),        'new_tests': response.get('new_tests')}]          print(tested_list)我的問題是所有代碼都運行。我希望,如果僅找到日期,則將顯示響應中的所有信息,如果找到日期和指示器,則僅顯示該指示器的特定信息。我的輸出是===================this is the response{'l_result': [{'deaths': 5, 'tested': 5,}]}===================tested: 5正如你所看到的,整個代碼的結果就在那里,我想要的只是tested: 5你能告訴我該怎么做嗎
查看完整描述

2 回答

?
慕斯709654

TA貢獻1840條經驗 獲得超5個贊

只是給了你一個簡單的例子,希望這對你的情況有幫助,這不是字典結構


date = '10/19/2020'

indicator = 'Y'


if  indicator =='Y' and date == '10/19/2020':

    print('Indicator is ',indicator)

elif date == '10/19/2020':

    print('Only date has a value')



print('2nd case when indicator is empty')


date = '10/19/2020'

indicator = None


if  indicator =='Y' and date == '10/19/2020':

    print('Indicator is ',indicator)

elif date == '10/19/2020':

    print('Only date has a value') 


查看完整回答
反對 回復 2023-12-05
?
慕慕森

TA貢獻1856條經驗 獲得超17個贊

從您提供的信息來看,您似乎必須使用邏輯運算“and”,然后有一個單獨的 for

if value('DATE'): 和 value('indicator')

埃利夫……


查看完整回答
反對 回復 2023-12-05
  • 2 回答
  • 0 關注
  • 154 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號