l1-068 调和平均 python
时间: 2023-10-19 11:30:01 浏览: 136
python打包程序win7 win10下运行丢失api-ms-win-crt-runtime-l1-1-0.dll的解决方法
5星 · 资源好评率100%
L1-068 调和平均是一个计算给定一系列正数的调和平均值的问题。调和平均值是指这些数的倒数的算数平均的倒数。在Python中,可以使用以下代码计算调和平均值:
a = int(input())
b = [eval(i) for i in input().split()]
sum = 0
for i in b:
sum += 1/i
print("%.2f" % (1/(sum/a)))
或者使用以下代码:
n = int(input())
print('%.2f' % (1/(sum([1/float(i) for i in input().split()])/n)))
这两段代码都可以计算给定一系列正数的调和平均值,并将结果保留两位小数进行输出。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [L1-068 调和平均 (10 分)python](https://blog.csdn.net/m0_61122217/article/details/122656419)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *3* [PTA L1-068:调和平均 (python)](https://blog.csdn.net/weixin_48062951/article/details/123294549)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文