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

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

對(duì)已解析的xml數(shù)據(jù)執(zhí)行計(jì)算時(shí),如何避免零錯(cuò)誤除法

對(duì)已解析的xml數(shù)據(jù)執(zhí)行計(jì)算時(shí),如何避免零錯(cuò)誤除法

達(dá)令說(shuō) 2021-03-16 09:13:59
請(qǐng)回答我,我已經(jīng)編碼了10天了。我在執(zhí)行代碼中的循環(huán)時(shí)遇到麻煩,但是我可以肯定的是,這是因?yàn)槲业玫搅嘶厮?。我使用以下代碼解析從url獲得的xml文件:pattern4 = re.compile('title=\'Naps posted: (.*) Winners:')pattern5 = re.compile('Winners: (.*)\'><img src=')for row in xmlload1['rows']:    cell = row["cell"]##### defining the Keys (key is the area from which data is pulled in the XML) for use   in the pattern finding/regex    user_delimiter = cell['username']    selection_delimiter = cell['race_horse']##### the use of the float here is to make sure the result of the strike rate calculations returns as a decimal, otherwise python 2 rounds to the nearest integer!     user_numberofselections = float(re.findall(pattern4, user_delimiter)[0])    user_numberofwinners = float(re.findall(pattern5, user_delimiter)[0])    strikeratecalc1 = user_numberofwinners/user_numberofselections    strikeratecalc2 = strikeratecalc1*100##### Printing the results of the code at hand    print "number of selections = ",user_numberofselections    print "number of winners = ",user_numberofwinners    print "Strike rate = ",strikeratecalc2,"%"    print ""getData()此代碼與其余代碼一起返回:number of selections =  112.0number of winners =  21.0Strike rate =  18.75 %number of selections =  146.0number of winners =  21.0Strike rate =  14.3835616438 %number of selections =  163.0number of winners =  55.0Strike rate =  33.7423312883 %現(xiàn)在,此xmlload的結(jié)果表明,只有三個(gè)用戶要解析,但是有第4個(gè)whos數(shù)據(jù)會(huì)讀取number of selections =  0number of winners =  0Strike rate =  0出于我的目的,對(duì)于沒(méi)有跟蹤記錄的用戶,沒(méi)有必要拉入用戶統(tǒng)計(jì)信息,我該如何使代碼跳過(guò)選擇0的用戶,或者至少使其不被零除的錯(cuò)誤不會(huì)影響要在循環(huán)中運(yùn)行的代碼?
查看完整描述

1 回答

?
心有法竹

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

continue找到0時(shí)僅使用a 。


user_numberofwinners = float(re.findall(pattern5, user_delimiter)[0])


# if the number of winners is 0, go to the next row to avoid division by 0

if user_numberofwinners == 0.0 : continue;


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

添加回答

舉報(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)