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

相关推荐
萧鼎16 分钟前
PDFMathTranslate:让数学公式在PDF翻译中不再痛苦
python·pdf
@_猿来如此18 分钟前
Django 实现电影推荐系统:从搭建到功能完善(附源码)
数据库·后端·python·django
鸿蒙布道师25 分钟前
鸿蒙NEXT开发正则工具类RegexUtil(ArkTs)
android·ios·华为·harmonyos·arkts·鸿蒙系统·huawei
CZIDC33 分钟前
[特殊字符][特殊字符] HarmonyOS相关实现原理聊聊![特殊字符][特殊字符]
华为·harmonyos
Python×CATIA工业智造1 小时前
爬虫技术入门:基本原理、数据抓取与动态页面处理
爬虫·python·pycharm
fmdpenny1 小时前
用python写一个相机选型的简易程序
开发语言·python·数码相机
敲敲敲-敲代码1 小时前
【PyCharm- Python- ArcGIS】:安装一个和 ArcGIS 不冲突的独立 Python让PyCharm 使用 (解决全过程记录)
python·arcgis·pycharm
猿榜编程2 小时前
python基础-requests结合AI实现自动化数据抓取
开发语言·python·自动化
一键三联啊2 小时前
【FastJSON】的parse与parseObject
linux·前端·python
shimly1234563 小时前
(done) 吴恩达版提示词工程 8. 聊天机器人 (聊天格式设计,上下文内容,点餐机器人)
人工智能·python·机器人