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

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

類型錯(cuò)誤 int 不可調(diào)用

類型錯(cuò)誤 int 不可調(diào)用

largeQ 2023-07-18 10:14:15
我正在嘗試編寫一個(gè)程序,該程序使用一個(gè)函數(shù)根據(jù)用戶輸入的信息計(jì)算單利。我收到一個(gè)類型錯(cuò)誤 - 'int' 不可調(diào)用。我認(rèn)為這個(gè)錯(cuò)誤只發(fā)生在你意外命名變量 int 時(shí),但我沒(méi)有這樣做,所以我不確定為什么我的程序中會(huì)出現(xiàn)這種類型的錯(cuò)誤。代碼如下,感謝任何指導(dǎo)!def accrued(p, r, n):    percent = r/100    total = p(1 + (percent*n))    return totalprincipal = int(input('Enter the principal amount: '))rate = float(input('Enter the anuual interest rate. Give it as a percentage: '))num_years = int(input('Enter the number of years for the loan: '))result = accrued(principal, rate, num_years)print(result)
查看完整描述

3 回答

?
慕桂英3389331

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

改變:

total = p(1 + (percent*n))

到:

total = p*(1 + (percent*n))

如果沒(méi)有*,p(...)則被解析為函數(shù)調(diào)用。由于整數(shù)被作為 傳遞p,因此它導(dǎo)致了您所看到的錯(cuò)誤。


查看完整回答
反對(duì) 回復(fù) 2023-07-18
?
海綿寶寶撒

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

您可以principal通過(guò) - 從用戶處獲取int(input(...))- 所以它是一個(gè)整數(shù)。然后你將它提供給你的函數(shù):

result = accrued(principal, rate, num_years)

作為第一個(gè)參數(shù) - 您的函數(shù)將第一個(gè)參數(shù)作為p

然后你做

total = p(1 + (percent*n))  # this is a function call - p is an integer

這就是你的錯(cuò)誤的根源:

類型錯(cuò)誤-“int”不可調(diào)用

通過(guò)提供像這樣的運(yùn)算符來(lái)修復(fù)它*

total = p*(1 + (percent*n))


查看完整回答
反對(duì) 回復(fù) 2023-07-18
?
翻翻過(guò)去那場(chǎng)雪

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

變化總計(jì) = p*(1 + (百分比*n))


def accrued(p, r, n):

    percent = r/100

    total = p*(1 + (percent*n)) # * missing 

    return total


principal = int(input('Enter the principal amount: '))

rate = float(input('Enter the anuual interest rate. Give it as a percentage: '))

num_years = int(input('Enter the number of years for the loan: '))

result = accrued(principal, rate, num_years)

print(result)


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

添加回答

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