华为机考入门python3--(0)测试题1-句子平均重量

分类:字符串

知识点:

  1. 获取输入 input().strip().split(" ")

  2. 拼接列表 " ".join(list)

  3. 输出指定位数的浮点数 print("%.2f" % value)

题目来自【华为招聘模拟考试】

图片

# 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: 软件工程小施同学

 

相关推荐

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-22 06:34:03       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-22 06:34:03       106 阅读
  3. 在Django里面运行非项目文件

    2024-01-22 06:34:03       87 阅读
  4. Python语言-面向对象

    2024-01-22 06:34:03       96 阅读

热门阅读

  1. Kubernetes(k8s)(一)

    2024-01-22 06:34:03       50 阅读
  2. Apache Wicket 9.10.0发布

    2024-01-22 06:34:03       63 阅读
  3. 网络安全产品之认识入侵防御系统

    2024-01-22 06:34:03       65 阅读
  4. ChatGPT与文心一言:谁更胜一筹?

    2024-01-22 06:34:03       53 阅读
  5. P8761 [蓝桥杯 2021 国 BC] 大写

    2024-01-22 06:34:03       40 阅读
  6. mini-spring-Bean含参实例化(三)

    2024-01-22 06:34:03       48 阅读