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

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

代碼將整數(shù)讀取為float

代碼將整數(shù)讀取為float

慕妹3242003 2021-05-12 14:09:00
我的代碼將iMid讀取為浮點(diǎn)并給出TypeError,即使將其包裝在整數(shù)函數(shù)中也是如此。另外,還有另一種方法來(lái)查找中間值的索引,這比我在這里嘗試的方法更容易嗎?def isIn(char, aStr):'''char: a single characteraStr: an alphabetized stringreturns: True if char is in aStr; False otherwise'''# Your code hereimport numpy as npdef iMid(x):    '''    x : a string    returns: index of the middle value of the string    '''    if len(x) % 2 == 0:        return int(np.mean(len(x)/2, (len(x)+2)/2)) #wrapped the                                                     # answer for iMid                                                     #in the integer function    else:        return int((len(x)+1)/2)if char == aStr[iMid] or char == aStr: #iMid is not being interpreted as an integer    return Trueelif char < aStr[iMid]:    return isIn(char, aStr[0:aStr[iMid]]) else:    return isIn(char, aStr[aStr[iMid]:])print(isIn('c', "abcd"))
查看完整描述

3 回答

?
呼如林

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

if char == aStr[iMid] or char == aStr: #iMid is not being interpreted as an integer

iMid不是整數(shù)。這是功能。

您需要調(diào)用該函數(shù)以獲取返回的整數(shù)。

if char == aStr[iMid(aStr)] or char == aStr: #iMid is called and returns an integer


查看完整回答
反對(duì) 回復(fù) 2021-05-18
?
白豬掌柜的

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

正如Doctorlove所說(shuō),aStr [iMid]正在使用函數(shù)iMid作為索引。因?yàn)閕Mid是一個(gè)功能對(duì)象。我認(rèn)為您應(yīng)該將所有aStr [iMid]替換為aStr [iMid(aStr)]


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

添加回答

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