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

相关推荐
landyjzlai2 小时前
蓝迪哥玩转Ai(8)---端侧AI:RK3588 端侧大语言模型(LLM)开发实战指南
人工智能·python
我叫黑大帅3 小时前
如何通过 Python 实现招聘平台自动投递
后端·python·面试
其实防守也摸鱼4 小时前
CTF密码学综合教学指南--第九章
开发语言·网络·python·安全·网络安全·密码学·ctf
砚底藏山河4 小时前
Python量化开发:2026最佳实时股票数据API接口推荐与对比
开发语言·windows·python
weixin_417197054 小时前
DeepSeek V4绑定华为:一场飞行中换引擎的国产算力革命
人工智能·华为
研究点啥好呢5 小时前
专为求职者开发的“面馆”!!!摆脱面试焦虑!!!
python·面试·开源·reactjs·求职招聘·fastapi
DFT计算杂谈5 小时前
自动化脚本一键绘制三元化合物相图
java·运维·服务器·开发语言·前端·python·自动化
EW Frontier6 小时前
6G ISAC新范式:基于智能漏波天线的Wi‑Fi通感一体化系统设计与实测【附MATLAB+python代码】
开发语言·python·matlab·music·isac·doa·wi‑fi
姚青&6 小时前
测试技术体系
java·python
易标AI6 小时前
标书智能体(五)——如何让弱模型也能稳定输出复杂json
人工智能·python·提示词·智能体·招投标