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

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

將浮點數(shù)四舍五入為一位小數(shù)(具體問題)

將浮點數(shù)四舍五入為一位小數(shù)(具體問題)

泛舟湖上清波郎朗 2021-11-02 15:25:01
我對 Python 很陌生,但對學(xué)習(xí)很感興趣。對于 uni Python 課程,我將創(chuàng)建一個程序,將溫度轉(zhuǎn)換為攝氏度或華氏度,并將轉(zhuǎn)換顯示為小數(shù)點后第一個位。我的問題在于我的打印線。正如您在我的代碼中看到的,我嘗試在連接時使用 round() 函數(shù)。雖然我試圖將浮點數(shù)轉(zhuǎn)換為 str(),但當(dāng)我運行我的程序時,出現(xiàn)以下錯誤。類型錯誤:類型 str 未定義圓形方法對于以下行打印 (round(str(temp), 1)+ " 攝氏度 = " + str(degF) + " 華氏度。")和我的 elif 集團中的打印線類似。任何幫助理解和解決問題將不勝感激。temp=float(input("Enter a temperature value to convert: "))unit=str(input("Convert to Fahrenheit or Celsius? Enter f or c: "))if unit=="c" or unit == "C":    degC=(temp)    temp=(1.8*temp)+32    print (round(str(temp), 1) + " degrees fahrenheit = " + str(degC) + " degrees Celsius. ")elif unit=="f" or unit == "F":    degF=(temp)    temp=(temp-32)/1.8    print (round(str(temp), 1)+ " degrees celsius = " + str(degF) + " degrees Fahrenheit. ")else:    print("you did not enter an f or c. Goodbye ")我的輸出應(yīng)該四舍五入到第一個小數(shù)位。
查看完整描述

3 回答

?
一只斗牛犬

TA貢獻1784條經(jīng)驗 獲得超2個贊

除非這是使用round函數(shù)的課堂作業(yè),否則我認為不需要round函數(shù)。

print ("%.1f degrees Celsius = %.1f degrees Fahrenheit" % (temp, degC))


查看完整回答
反對 回復(fù) 2021-11-02
?
Helenr

TA貢獻1780條經(jīng)驗 獲得超4個贊

不要轉(zhuǎn)換temp為字符串。將其保留為round. 將結(jié)果 afterround變成strfor 連接

str(round(temp, 1))


查看完整回答
反對 回復(fù) 2021-11-02
?
蕭十郎

TA貢獻1815條經(jīng)驗 獲得超13個贊

您的操作順序錯誤。先舍入,轉(zhuǎn)換為字符串:

print (str(round(temp), 1)+ " degrees celsius = " ...


查看完整回答
反對 回復(fù) 2021-11-02
  • 3 回答
  • 0 關(guān)注
  • 179 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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