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

相关推荐
用户0332126663674 分钟前
使用 Python 设置 Excel 文件属性
python
jyOverQ11 分钟前
LangGraph Agent 模式详解:从自主决策到 Tool Calling 执行链
python·langchain
青 春 记 忆12 分钟前
LeetCode 226. 翻转二叉树|Python 解法详解
python·算法·leetcode
小女孩真可爱16 分钟前
GPT(1)----------从零实现 GPT 模型以生成文本
人工智能·python·gpt·nlp
码云骑士18 分钟前
116-Python调用GPT-4V分析图片-Base64编码-多图-JSON结构化输出
开发语言·python·json
超爱西西鸭19 分钟前
ArkTS延安精神学习应用:四版块 + 三组展开状态 + 大事记时间轴
学习·华为·harmonyos·鸿蒙
老郑聊AI业财智造22 分钟前
TensorFlow 技术架构与源码分析
人工智能·python·深度学习·架构·tensorflow·软件工程
民乐团扒谱机24 分钟前
【微科普】压缩感知(CS):违反了奈奎斯特采样定理?不先采集也能还原信号?大白话讲透稀疏采样、L1重建与OMP,一文吃透附代码
python·神经网络·线性代数·算法·数学建模·压缩感知·奈奎斯特
承渊政道25 分钟前
【Python编程—从入门到实践】(Python操作列表深度教程:循环、切片、元组与代码风格)
开发语言·python·pycharm·列表·元组·切片
guwentian29 分钟前
一文搞懂 AI Agent 安全护栏:用 Python 手写工具网关,把越权挡在执行层
人工智能·python·安全