安全问答

安全问答是一个知识全球问答,包含丰富的问答知识

首页 常规 游戏 娱乐 科技 程序员

用python编写程序完成通讯录查询功能。‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬1 从文件phonenumtxt中读入电话通讯录。每行格式如下 :‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬

  • 日期: 2026-02-23
  • 标签: 财经

读取文件内容并存入字典中

with open("phonenum.txt", "r", encoding="utf-8") as f: lines = f.readlines() phonenum_dict = {} for line in lines: name, phone = line.strip().split() phonenum_dict[name] = phone

查询功能

name = input("请输入姓名:") if name in phonenum_dict: print("{}:{}".format(name, phonenum_dict[name])) else: print("数据不存在")

用python编写程序完成通讯录查询功能。‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬1 从文件phonenumtxt中读入电话通讯录。每行格式如下 :‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬

原文地址: https://www.cveoy.top/t/topic/g0hK 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录

  • 上一篇: 贵州盛华职业学院酒店管理专业怎么样?就业前景、师资、设施一览
  • 下一篇: 开远第一职业高级中学平面广告设计与制作专业怎么样?

© 2019 • 2025 - 安全问答 站长邮箱:wxgpt@qq.com    ICP备案/许可证号:豫ICP备2024104334号-2