python实现简单的名字管理系统_python列表使用实现名字管理系统
python列表使用實現名字管理系統
來源:中文源碼網????瀏覽: 次????日期:2019年11月5日
【下載文檔:??python列表使用實現名字管理系統.txt?】
(友情提示:右鍵點上行txt文檔名->目標另存為)
python列表使用實現名字管理系統本文實例為大家分享了python列表使用實現名字管理系統的具體代碼,供大家參考,具體內容如下
實現的功能代碼如下:
# 名字管理系統 列表的使用
print("="*50)
print("1:添加名字")
print("2:修改名字")
print("3:查詢名字")
print("4:刪除名字")
print("5:退出")
print("="*50)
names = []
while True:
num = int(input("請輸入要操作的序號:")) # input獲取到的是str,要轉換為Int
if num == 1:
name_add = input("請輸入要添加的名字:")
names.append(name_add)
print(names)
elif num == 2:
name_edit1 = input("請輸入要修改的原始名字")
# 法一:
# if name_edit1 in names:
# for i in range(len(names)):
# if name_edit1 == names[i]:
# name_edit2 = input("請輸入要修改為的名字:")
# names[i] = name_edit2
# print("修改成功!")
# else:
# print("查無此人")
# 法二:
find_name = 0 # 默認沒找到
for i in range(len(names)):
if name_edit1 == names[i]:
name_edit2 = input("請輸入要修改為的名字:")
names[i] = name_edit2
print("修改成功!")
find_name = 1
if find_name = 0:
print("查無此人")
elif num == 3:
name_select = input("請輸入要查詢的名字:")
if name_select in names:
print("找到了要查找的人")
else:
print("查無此人")
elif num == 4:
name_del = input("請輸入要進行刪除的名字:")
if name_del in names:
names.remove(name_del)
print("刪除成功!")
else:
print("查無此人,無法進行刪除")
elif num == 5:
break
else:
print("輸入錯誤!")
小編再為大家分享另一段用python中列表實現名字管理系統的代碼:1、打印功能提示
2、獲取用戶輸入
3、根據用戶的輸入選擇相應的功能進行實現#打印提示
print("="*50)
print("names_manage_systme")
print("1、add a new name")
print("2、delete a name")
print("3、modify a name")
print("4、search a name")
print("5、quit!")
print("="*50)#存儲用戶姓名
names = []while True:
#獲取用戶輸入
user_input_num = int(input("please input the number you need:"))
#功能實現
if user_input_num == 1: #增加
new_name = input("please input the new name that you need to add:")
names.append(new_name)
print(names)
elif user_input_num == 2: #刪除
del_name = input("please input the new name that you need to delete:")
names.remove(del_name)
print(names)
elif user_input_num == 3: #改
modify_name = input("please input the new name that you need to modify:")
after_modify_name = input("please input the new name :")
length = len(names)
modify_name_index = 0
i = 0
while i < length:
if modify_name == names[i]:
modify_name_index = i
break
i += 1
names[modify_name_index] = after_modify_name
print(names) elif user_input_num == 4: #查找
search_name = input("please input the new name that you need to search:")
length = len(names)
search_name_index = 0
i = 0
while i < length:
if search_name == names[i]:
search_name_index = i
break
i += 1
if i == length:
search_name_index = -1 #沒有找到的話令索引置為-1
print("the index of your search_name is:%d"%search_name_index) elif user_input_num == 5: #退出
print("quit success!")
break
else:
print("input number wrong!\nplease input again")以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持中文源碼網。
親,試試微信掃碼分享本頁!?*^_^*
總結
以上是生活随笔為你收集整理的python实现简单的名字管理系统_python列表使用实现名字管理系统的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: tcc读写文本txt文件
- 下一篇: MySQL建立多选一列表_如何实现自定义