华为机考入门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: 软件工程小施同学

相关推荐
子琦啊2 分钟前
华为 OD 2026年5月笔试题解析
javascript·华为
轮子飞了18 分钟前
记一次 Spring AI Alibaba + 百炼的踩坑:结构化输出与联网搜索的冲突
人工智能·python·spring
专注VB编程开发20年23 分钟前
VB.NET是唯一能直接打击 Python 的语言
python
梦想三三28 分钟前
【NLP入门到实战】TF-IDF算法详解 + 红楼梦120回关键词提取
人工智能·python·计算机视觉
弹简特29 分钟前
【零基础学Python】05-Python函数完全指南:从初阶定义到进阶参数,一篇打通核心难点
开发语言·python
学地理的小胖砸1 小时前
【批量处理tiff文件生成jpg缩略图】
数据库·人工智能·python
机汇五金_1 小时前
通信设备防雨箱如何兼顾防护与散热?
网络·python
yuegu7771 小时前
HarmonyOS应用<节气通>开发第4篇:TabBar导航实现
华为·harmonyos
糖果店的幽灵1 小时前
LangChain 1.3 完全教程:从入门到精通-Part 7: Documents(文档处理)
java·python·langchain
Wonderful U1 小时前
基于Python爬虫+Django的轻量化天气预报系统:从数据抓取到可视化展示的完整实战
爬虫·python·django