Python 四舍五入到三位小数
Rounding to three decimals in Python
我有一个要求我四舍五入的代码问题的答案
第 1 部分:在下面的单元格中编写一行代码,显示以下句子的基于词典的情感极性分数:'Hiking in the mountains is fun and very relaxing.'
第 2 部分:句子 'Hiking in the mountains is fun and very relaxing.' 的基于词典的情感极性得分是多少?报告您的答案使用三位小数 精度(例如 0.321)。**
如何在代码片段中为此添加舍入函数?
get_lexicon_polarity('Hiking in the mountains is fun and very relaxing')
我知道我总是可以这样回答:
np.round(0.2310364009813431, 3)
但是 - 我想知道如何在原始代码中调用它。
这里有 2 种方式:
1:将get_lexicon_polarity的结果赋值给一个变量,然后把变量传给np.round
lexicon_polarity = get_lexicon_polarity('Hiking in the mountains is fun and very relaxing')
np.round(lexicon_polarity, 3)
2:将带参数的函数作为入参传递给np.round
np.round(get_lexicon_polarity('Hiking in the mountains is fun and very relaxing'), 3)
我有一个要求我四舍五入的代码问题的答案
第 1 部分:在下面的单元格中编写一行代码,显示以下句子的基于词典的情感极性分数:'Hiking in the mountains is fun and very relaxing.'
第 2 部分:句子 'Hiking in the mountains is fun and very relaxing.' 的基于词典的情感极性得分是多少?报告您的答案使用三位小数 精度(例如 0.321)。**
如何在代码片段中为此添加舍入函数?
get_lexicon_polarity('Hiking in the mountains is fun and very relaxing')
我知道我总是可以这样回答:
np.round(0.2310364009813431, 3)
但是 - 我想知道如何在原始代码中调用它。
这里有 2 种方式:
1:将get_lexicon_polarity的结果赋值给一个变量,然后把变量传给np.round
lexicon_polarity = get_lexicon_polarity('Hiking in the mountains is fun and very relaxing')
np.round(lexicon_polarity, 3)
2:将带参数的函数作为入参传递给np.round
np.round(get_lexicon_polarity('Hiking in the mountains is fun and very relaxing'), 3)