python名片管理脚本

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

list1 = []

def prints():
print("*" * 50)
print("please input:\n "
"1)-add \n "
"2)-delete \n "
"3)-find_all \n "
"4)-find_one \n",
"5)-exit")
print("*" * 50)

def add():
num_i = 0
while num_i < 3:
name = input("please input name: ").strip()
email = input("please input email: ").strip()
phone = input("please input phone: ").strip()

if phone.isdecimal() != True:
num_i = num_i + 1
print("your error is %d" %num_i)

dict2 = {"name":name,
"email":email,
"phone":phone}

list1.append(dict2)
break
else:
print("your error is 3 program exit by by!")
exit()

def deletes():
name = input("please select you del is name: ").strip()
i = 0
for temp in list1:
i = i + 1
if name in temp["name"]:
list1.pop(i - 1)
print("del successful %s" % name)
break
else:
print("del error %s" % name)

def find_all():

print("-" * 50)
print("功能:显示全部")

for name in ["name", "email", "phone"]:
print(name, end = "\t\t")

print("")
print("=" * 50)

for card_dict in list1:
print("%s\t\t%s\t\t%s" % (card_dict["name"],
card_dict["email"],
card_dict["phone"]))

def find_one():
print("name\t\t","email\t\t","phone\t\t")
print("=" * 50)
find_name = input("please your find name: ").strip()

for dict2 in list1:
if dict2["name"] == find_name:
print("%s\t\t%s\t\t%s" % (dict2["name"],
dict2["email"],
dict2["phone"]))
mod_del(dict2)
else:
print("find failed!")
break

def mod_del(dict3):

modificotion_del = input("please select modification or del or exit: "
"(1)modification \t (2)del \t (3)exit ").strip()

if modificotion_del == "1":

dict3["name"] = modification(dict3["name"],"name(not modification press ENTER): ")

dict3["email"] = modification(dict3["email"],"email(not modification press ENTER): ")

dict3["phone"] = modification(dict3["phone"],"phone(not modification press ENTER): ")

elif modificotion_del == "2":
list1.remove(dict3)
print("del successful")

elif modificotion_del == "3":
main()

def modification(old_dict,messagebox):

result = input(messagebox)

if len(result) > 0:
return result
else:
return old_dict



def main():
try:
num_ii = 0
while num_ii< 3:
prints()
number = input("please input your option is: ").strip()

if number == "1":
add()
elif number == "2":
deletes()
elif number == "3":
find_all()
elif number == "4":
find_one()
elif number == "5":
exit()
else:
num_ii = num_ii + 1
print("your input error is %d next! " %num_ii)

else:
print("your input error is 3 next ,program exit by by!")
exit()
except Exception as buff:
print("unknown error: %s" %buff)

if __name__ == "__main__":
main()