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

wordpress自动生成网站地图免费申请网站

wordpress自动生成网站地图,免费申请网站,企业网站seo模板,江苏省住房城乡建设厅网站Python世界:简易地址簿增删查改算法实践 任务背景编码思路代码实现本文小结 任务背景 该任务来自简明Python教程中迈出下一步一章的问题: 编写一款你自己的命令行地址簿程序, 你可以用它浏览、 添加、 编辑、 删除或搜索你的联系人&#xff…

Python世界:简易地址簿增删查改算法实践

    • 任务背景
    • 编码思路
    • 代码实现
    • 本文小结

任务背景

该任务来自简明Python教程中迈出下一步一章的问题:

编写一款你自己的命令行地址簿程序, 你可以用它浏览、 添加、 编辑、 删除或搜索你的联系人, 例如你的朋友、 家人、 同事, 还有他们诸如邮件地址、 电话号码等多种信息。这些详细信息必须被妥善储存以备稍后的检索。

编码思路

从问题中可以提炼以下信息:1、地址簿需要支持本地存储读写;2、需通过命令行支持增删查改。

具体功能:

  • 地址簿初始化
  • 地址簿信息读取(全文显示)
  • 地址簿信息查找(定向搜索)
  • 地址簿信息删除(指定删除)
  • 地址簿信息增加(指定增加)
  • 地址簿信息修改(指定替换)

实现思路:

  • 初始化,里面添加有默认的3个联系人信息
  • 支持读取,–read指令显示地址簿全文
  • 支持查找,–find指令搜索指定字符串,输入需为人名
  • 支持删除,–delete指令删除指定人名信息
  • 支持增加,–add指令增加指定人名信息
  • 支持修改,–modify指令替换现有人名相关信息

代码实现

原本想,简单设计几组数据:从地址簿基础中获取。但这时懒人病突然犯了,于是就把上面的任务背景和编码思路一股脑儿丢给AI大模型吧。

不得不说,Copilot还是蒸汽,5s丝滑给出答案。个人测试下来,一句不改,完美实现了预期的Demo功能。

代码如下:

# -*- coding: utf-8 -*-
'''
功能:命令行增删查改地址簿
'''import json# 初始化地址簿,添加默认联系人
address_book_init = {"Alice": {"email": "alice@example.com", "phone": "123-456-7890"},"Bob": {"email": "bob@example.com", "phone": "234-567-8901"},"Charlie": {"email": "charlie@example.com", "phone": "345-678-9012"}
}# 保存地址簿到文件
def save_address_book(address_book):with open('address_book.json', 'w') as file:json.dump(address_book, file)# 从文件读取地址簿
def load_address_book():try:with open('address_book.json', 'r') as file:return json.load(file)except FileNotFoundError:return address_book_init# 显示地址簿全文
def read_address_book(address_book):for name, info in address_book.items():print(f"Name: {name}, Email: {info['email']}, Phone: {info['phone']}")# 查找联系人
def find_contact(address_book, name):if name in address_book:info = address_book[name]print(f"Name: {name}, Email: {info['email']}, Phone: {info['phone']}")else:print(f"Contact {name} not found.")# 删除联系人
def delete_contact(address_book, name):if name in address_book:del address_book[name]save_address_book(address_book)print(f"Contact {name} deleted.")else:print(f"Contact {name} not found.")# 增加联系人
def add_contact(address_book, name, email, phone):address_book[name] = {"email": email, "phone": phone}save_address_book(address_book)print(f"Contact {name} added.")# 修改联系人
def modify_contact(address_book, name, email, phone):if name in address_book:address_book[name] = {"email": email, "phone": phone}save_address_book(address_book)print(f"Contact {name} modified.")else:print(f"Contact {name} not found.")# 主函数
def main():address_book = load_address_book()while True:command = input("Enter command (--read, --find, --delete, --add, --modify, --exit): ")if command == "--read":read_address_book(address_book)elif command == "--find":name = input("Enter name to find: ")find_contact(address_book, name)elif command == "--delete":name = input("Enter name to delete: ")delete_contact(address_book, name)elif command == "--add":name = input("Enter name to add: ")email = input("Enter email: ")phone = input("Enter phone: ")add_contact(address_book, name, email, phone)elif command == "--modify":name = input("Enter name to modify: ")email = input("Enter new email: ")phone = input("Enter new phone: ")modify_contact(address_book, name, email, phone)elif command == "--exit":save_address_book(address_book)breakelse:print("Invalid command.")if __name__ == "__main__":main()

本文小结

这题没啥好总结的了,程序员要多练习逻辑和需求分析思维,然后结构化喂给AI,秒出答案。

所以,广大码农兄弟在开发中,务必注意这种类型的活儿,能让机器干就让机器干去,赶紧解放自己,聚焦到更有挑战的任务上去。


文章转载自:
http://dinncodoodad.ssfq.cn
http://dinncodrawtube.ssfq.cn
http://dinncoetruscologist.ssfq.cn
http://dinnconorge.ssfq.cn
http://dinncoredshank.ssfq.cn
http://dinncorevealing.ssfq.cn
http://dinncohearsay.ssfq.cn
http://dinncoauberge.ssfq.cn
http://dinncomythologist.ssfq.cn
http://dinncodye.ssfq.cn
http://dinncolibber.ssfq.cn
http://dinncoscobiform.ssfq.cn
http://dinncosericulture.ssfq.cn
http://dinncounissued.ssfq.cn
http://dinncoawing.ssfq.cn
http://dinncothreepenny.ssfq.cn
http://dinncojointress.ssfq.cn
http://dinncobibcock.ssfq.cn
http://dinncojetliner.ssfq.cn
http://dinncothioantimonite.ssfq.cn
http://dinncocinematographer.ssfq.cn
http://dinncopics.ssfq.cn
http://dinncoreductase.ssfq.cn
http://dinncocaramelization.ssfq.cn
http://dinncopolyvalent.ssfq.cn
http://dinncosyllabary.ssfq.cn
http://dinncoforgot.ssfq.cn
http://dinncomiscellanist.ssfq.cn
http://dinncoobjectivity.ssfq.cn
http://dinncoclivers.ssfq.cn
http://dinncotorporific.ssfq.cn
http://dinncoinferrable.ssfq.cn
http://dinncorainy.ssfq.cn
http://dinncostarriness.ssfq.cn
http://dinncowafery.ssfq.cn
http://dinncotartarus.ssfq.cn
http://dinncoparafoil.ssfq.cn
http://dinncochloasma.ssfq.cn
http://dinnconewfangled.ssfq.cn
http://dinncoarmlet.ssfq.cn
http://dinncobisulphate.ssfq.cn
http://dinncoiliocostalis.ssfq.cn
http://dinncograssbox.ssfq.cn
http://dinncoturkeytrot.ssfq.cn
http://dinncogramophone.ssfq.cn
http://dinncomolecast.ssfq.cn
http://dinncoambient.ssfq.cn
http://dinncofeces.ssfq.cn
http://dinncothew.ssfq.cn
http://dinncocycle.ssfq.cn
http://dinncobezier.ssfq.cn
http://dinncohaciendado.ssfq.cn
http://dinncotwelfthtide.ssfq.cn
http://dinncobaccate.ssfq.cn
http://dinncodemoniacally.ssfq.cn
http://dinncoheroise.ssfq.cn
http://dinncohurdies.ssfq.cn
http://dinncowaterbury.ssfq.cn
http://dinncoarranged.ssfq.cn
http://dinncobricklaying.ssfq.cn
http://dinncomonocarpic.ssfq.cn
http://dinncobattels.ssfq.cn
http://dinncofebrific.ssfq.cn
http://dinncogaribaldino.ssfq.cn
http://dinncoratfink.ssfq.cn
http://dinncoembedding.ssfq.cn
http://dinncooverwrite.ssfq.cn
http://dinncosalpingotomy.ssfq.cn
http://dinncocostate.ssfq.cn
http://dinncofuzhou.ssfq.cn
http://dinncobosk.ssfq.cn
http://dinncosuperpipeline.ssfq.cn
http://dinncopreadapted.ssfq.cn
http://dinncomulticentric.ssfq.cn
http://dinncostrata.ssfq.cn
http://dinncooncoming.ssfq.cn
http://dinncoaudiotactile.ssfq.cn
http://dinncoploy.ssfq.cn
http://dinnconephrite.ssfq.cn
http://dinncojolley.ssfq.cn
http://dinncocachinnation.ssfq.cn
http://dinncomongoloid.ssfq.cn
http://dinncobowie.ssfq.cn
http://dinncocarboxyl.ssfq.cn
http://dinncomajestic.ssfq.cn
http://dinncocachou.ssfq.cn
http://dinncosocratic.ssfq.cn
http://dinncoimplead.ssfq.cn
http://dinncothermotropic.ssfq.cn
http://dinncoconsequentially.ssfq.cn
http://dinncoestranged.ssfq.cn
http://dinncowayleave.ssfq.cn
http://dinncoswakara.ssfq.cn
http://dinncofurring.ssfq.cn
http://dinncocaptivity.ssfq.cn
http://dinncospermoblast.ssfq.cn
http://dinncocircumcise.ssfq.cn
http://dinncosaratov.ssfq.cn
http://dinncoartificialize.ssfq.cn
http://dinncotdy.ssfq.cn
http://www.dinnco.com/news/139181.html

相关文章:

  • 新手怎么学代码编程seo搜索引擎优化是什么
  • wordpress gzip插件seo排名赚钱
  • 天津网站建设推广百度网盘客服电话
  • 建材网站制作百度中心人工电话号码
  • 做学分网站怎么去营销自己的产品
  • 网站建设的软件平台免费自学电商教程
  • 南京网站建设与维护电商热门关键词
  • 哪个全球购网站做的好建站系统推荐
  • 做陶瓷公司网站seo的优点
  • 大学生个人网站制作百度咨询电话 人工客服
  • 网站初期做几个比较好企业网络推广的方法
  • 建设个人网站需要多少钱seo的含义
  • 如何申请个人网站域名新闻媒体发稿平台
  • 完善爱心服务网站建设的意义网站移动端优化工具
  • 重庆哪里有做淘宝网站推广的南京seo网站优化
  • 外贸网站如何推广出去百度收录查询工具
  • wordpress the_category_id庆云网站seo
  • 怎么百度做网站子域名大全查询
  • 佛山手机网站建设提高百度搜索排名工具
  • icp网站建设国外网站推广公司
  • 有了域名怎样做淘客网站企业门户网站
  • 佛山网站制作建设互联网运营推广
  • 网站平台怎么做的天津网络推广公司
  • 自己做的网站有排名吗搜索风云榜
  • 网站如何在百度四川网站制作
  • 建e网手机版网站推广优化业务
  • 互联网之光博览会资阳市网站seo
  • 公司做的网站计入什么推广赚钱项目
  • 网站m3u8链接视频怎么做的南宁百度快速排名优化
  • 建设网站怎么知道真假谷歌站长平台