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

相关推荐
honder试试25 分钟前
焊接自动化测试平台图像处理分析-模型训练推理
开发语言·python
心本无晴.42 分钟前
Python进程,线程
python·进程
爱笑的眼睛112 小时前
HarmonyOS 应用开发新范式:深入剖析 Stage 模型与 ArkTS 状态管理
华为·harmonyos
java1234_小锋3 小时前
Scikit-learn Python机器学习 - 特征降维 压缩数据 - 特征提取 - 主成分分析 (PCA)
python·机器学习·scikit-learn
java1234_小锋3 小时前
Scikit-learn Python机器学习 - 特征降维 压缩数据 - 特征提取 - 线性判别分析 (LDA)
python·机器学习·scikit-learn
爱笑的眼睛114 小时前
深入浅出 HarmonyOS ArkUI 3.0:基于声明式开发范式与高级状态管理构建高性能应用
华为·harmonyos
思辨共悟4 小时前
Python的价值:突出在数据分析与挖掘
python·数据分析
计算机毕业设计木哥5 小时前
计算机毕设选题:基于Python+Django的B站数据分析系统的设计与实现【源码+文档+调试】
java·开发语言·后端·python·spark·django·课程设计
中等生5 小时前
Pandas 与 NumPy:数据分析中的黄金搭档
后端·python
电手5 小时前
时隔4年麒麟重新登场!华为这8.8英寸新「手机」给我看麻了
华为·智能手机