华为机考入门python3--(0)测试题1-句子平均重量

分类:字符串

知识点:

  1. 获取输入 input().strip().split(" ")

  2. 拼接列表 " ".join(list)

  3. 输出指定位数的浮点数 print("%.2f" % value)

题目来自【华为招聘模拟考试】

python 复制代码
# If you need to import additional packages or classes, please import here.

def func():

    # please define the python3 input here. For example: a,b = map(int, input().strip().split())
    words = input().strip().split(" ")
    # please finish the function body here.
    total_words = len(words)
    new_str = "".join(words)
    total_length = len(new_str)
    # please define the python3 output here. For example: print().
    # print(round(total_length/total_words, 2)) # round有bug
    print("%.2f" % (total_length/total_words))

if __name__ == "__main__":
    func()

注意,不要使用round,有bug

by: 软件工程小施同学

相关推荐
程序员小刘30 分钟前
【HarmonyOS 5】教育开发实践详解以及详细代码案例
华为·wpf·harmonyos
程序员三藏1 小时前
如何使用Jmeter进行压力测试?
自动化测试·软件测试·python·测试工具·jmeter·测试用例·压力测试
carpell1 小时前
【语义分割专栏】3:Segnet原理篇
人工智能·python·深度学习·计算机视觉·语义分割
24K纯学渣1 小时前
Python编码格式化之PEP8编码规范
开发语言·ide·python·pycharm
怒视天下1 小时前
零基础玩转Python生物信息学:数据分析与算法实现
开发语言·python
zhanshuo1 小时前
Python元组黑科技:3招让数据安全暴增200%,学生管理系统实战揭秘!
python
空中湖1 小时前
免费批量图片格式转换工具
图像处理·python·程序人生
Mantanmu2 小时前
Python训练day40
人工智能·python·机器学习
天天爱吃肉82182 小时前
新能源汽车热管理核心技术解析:冬季续航提升40%的行业方案
android·python·嵌入式硬件·汽车
ss.li2 小时前
TripGenie:畅游济南旅行规划助手:个人工作纪实(二十二)
javascript·人工智能·python