当前位置: 首页 > news >正文

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

分类:字符串

知识点:

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

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

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

  4. len() 函数对于很多内置的数据类型都适用,它返回对象的元素个数或长度。

# 用法1: 获取字符串的长度
string_example = "Hello, World!"
length_of_string = len(string_example)
print("字符串的长度为:", length_of_string)# 用法2: 获取列表或元组的元素个数
list_example = [1, 2, 3, 4, 5]
length_of_list = len(list_example)
print("列表的元素个数为:", length_of_list)# 用法3: 获取字典的键值对个数
dictionary_example = {"a": 1, "b": 2, "c": 3}
length_of_dictionary = len(dictionary_example)
print("字典的键值对个数为:", length_of_dictionary)# 用法4: 获取集合的元素个数
set_example = {1, 2, 3, 4, 5}
length_of_set = len(set_example)
print("集合的元素个数为:", length_of_set)# 用法5: 获取其他可迭代对象的元素个数
tuple_example = (1, 2, 3, 4, 5)
length_of_tuple = len(tuple_example)
print("元组的元素个数为:", length_of_tuple)

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

图片

# 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有bugprint("%.2f" % (total_length/total_words))if __name__ == "__main__":func()

注意,不要使用round,有bug

by: 软件工程小施同学

http://www.lryc.cn/news/288499.html

相关文章:

  • Linux--基础开发工具篇(1)(yum)
  • 循环测试之旅——深度解析Pytest插件 pytest-repeat
  • Java - OpenSSL与国密OpenSSL
  • 谷粒商城【成神路】-【1】——项目搭建
  • yml配置文件怎么引用pom.xml中的属性
  • SEW MOVIFIT变频一体机配置
  • nginx反向代理负载均衡
  • 项目中日历管理学习使用
  • 【单片机】使用AD2S1210旋变芯片读取转子位置和速度
  • EasyExcel实现导出图片到excel
  • Cybellum—信息安全测试工具
  • 六、Kotlin 类型进阶
  • Chrome 浏览器插件 runtime 字段解析
  • 七分钟交友匿名聊天室源码
  • Aleo项目详细介绍-一个兼顾隐私和可编程性的隐私公链
  • qt学习:实战 http请求获取qq的吉凶
  • 【NodeJS JS】动态加载字体的各方式及注意事项;
  • 每次请求sessionid变化【SpringBoot+Vue】
  • 勤学苦练“prompts“,如沐春风“CodeArts Snap“
  • springboot(ssm线上医院挂号系统 在线挂号预约系统Java系统
  • 万界星空科技可视化数据大屏的作用
  • 5月22日比特币披萨日,今天你吃披萨了吗?
  • 内网穿透、远程桌面、VPN的理解
  • 如何发布自己的npm包,详细流程
  • 【书生·浦语大模型实战】“PDF阅读小助手”学习笔记
  • 用ChatGPT写申请文书写进常春藤联盟?
  • uni-app导航栏自定义“返回按钮”多种方法设置原生返回
  • 【kubernets】kubelet证书单独更新
  • 【STM32】STM32学习笔记-硬件SPI读写W25Q64(40)
  • 防御保护---安全策略