
model=input("model:")
if model=='1':
print("好友添加:",end='')
new_friend=input("newfriend:name,number,address")
friend_n=list(new_friend.split(','))
friend[friend_n[0]] =friend_n[1:3] # 添加
# friend4=dict.fromkeys([friend_n[0]],friend_n[1:3])
print("friend: ", friend)
elif model=='2':
print("好友删除:",end='')
new_friend = input("name")
# del friend[ new_friend] # 删除键是'Name'的条目
try:
friend.pop(new_friend)
print("friend: ", friend)
except:
print("查无此人")
elif model=='3':
print("好友修改:", end='')
new_friend = input("name")
friend[new_friend]=list(input("number,address").split(','))
print("friend: ", friend)
else:
print("好友查询:", end='')
new_friend = input("name")
try:
print(new_friend,':', friend[new_friend])
except:
print("查无此人")
以上程序包含了整个流程,有删赠改查功能,还有利用异常处理的处理过程。
可以将数据存储在列表里然后再将列表保存到文件里
通过对列表的 *** 作动态更改存储在文件里的内容
如果有文件的话程序启动时从文件里加载数据保存到列表即可
如果代码不想自己写的话
我可以有偿代劳
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)