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

相关推荐
智算菩萨14 分钟前
OpenCV色彩空间转换实战:BGR转HSV/LAB的工业应用场景详解(含自动化脚本)
人工智能·python·opencv·计算机视觉·自动化·音视频
曲幽16 分钟前
别再数据线了!用FastAPI 5分钟搭个局域网文件+剪贴板神器
python·fastapi·web·async·clipboard·fileupload
AbsoluteLogic19 分钟前
Python——必学内置模块 OS
python
sqyno1sky23 分钟前
游戏与图形界面(GUI)
jvm·数据库·python
用户83562907805128 分钟前
Python 实现 Word 文档图片插入与排版技巧
后端·python
2501_9454235437 分钟前
持续集成/持续部署(CI/CD) for Python
jvm·数据库·python
m0_6214385238 分钟前
用Python实现自动化的Web测试(Selenium)
jvm·数据库·python
2301_804215411 小时前
Python多线程与多进程:如何选择?(GIL全局解释器锁详解)
jvm·数据库·python
晚霞的不甘1 小时前
HarmonyOS ArkTS 进阶实战:深入理解边距、边框与嵌套布局
前端·计算机视觉·华为·智能手机·harmonyos
大鹏说大话1 小时前
Java 并发基石:CAS 原理深度解析与 ABA 问题终极解决方案
开发语言·python