python列表使用實(shí)現(xiàn)名字管理系統(tǒng)
本文實(shí)例為大家分享了python列表使用實(shí)現(xiàn)名字管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
實(shí)現(xiàn)的功能代碼如下:
# 名字管理系統(tǒng) 列表的使用
print("="*50)
print("1:添加名字")
print("2:修改名字")
print("3:查詢名字")
print("4:刪除名字")
print("5:退出")
print("="*50)
names = []
while True:
num = int(input("請輸入要操作的序號:")) # input獲取到的是str,要轉(zhuǎn)換為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 # 默認(rèn)沒找到
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("請輸入要進(jìn)行刪除的名字:")
if name_del in names:
names.remove(name_del)
print("刪除成功!")
else:
print("查無此人,無法進(jìn)行刪除")
elif num == 5:
break
else:
print("輸入錯誤!")
小編再為大家分享另一段用python中列表實(shí)現(xiàn)名字管理系統(tǒng)的代碼:
1、打印功能提示
2、獲取用戶輸入
3、根據(jù)用戶的輸入選擇相應(yīng)的功能進(jìn)行實(shí)現(xiàn)
#打印提示
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:"))
#功能實(shí)現(xiàn)
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")
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- python圖書管理系統(tǒng)
- Python實(shí)現(xiàn)GUI學(xué)生信息管理系統(tǒng)
- python實(shí)現(xiàn)圖書管理系統(tǒng)
- Python實(shí)現(xiàn)學(xué)生成績管理系統(tǒng)
- python學(xué)生信息管理系統(tǒng)
- python實(shí)現(xiàn)學(xué)生信息管理系統(tǒng)
- Python學(xué)生成績管理系統(tǒng)簡潔版
- python實(shí)現(xiàn)外賣信息管理系統(tǒng)
- python實(shí)現(xiàn)員工管理系統(tǒng)
- python版學(xué)生管理系統(tǒng)
相關(guān)文章
利用Python進(jìn)行數(shù)據(jù)清洗的操作指南
數(shù)據(jù)清洗是指發(fā)現(xiàn)并糾正數(shù)據(jù)文件中可識別的錯誤的最后一道程序,包括檢查數(shù)據(jù)一致性,處理無效值和缺失值等。本文為大家介紹了Python進(jìn)行數(shù)據(jù)清洗的操作詳解,需要的可以參考一下2022-03-03
簡單了解python關(guān)系(比較)運(yùn)算符
這篇文章主要介紹了簡單了解python關(guān)系(比較)運(yùn)算符,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2019-07-07
python Tcp協(xié)議發(fā)送和接收信息的例子
今天小編就為大家分享一篇python Tcp協(xié)議發(fā)送和接收信息的例子,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-07-07
pandas 實(shí)現(xiàn)字典轉(zhuǎn)換成DataFrame的方法
今天小編就為大家分享一篇pandas 實(shí)現(xiàn)字典轉(zhuǎn)換成DataFrame的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-07-07
用Python進(jìn)行TCP網(wǎng)絡(luò)編程的教程
這篇文章主要介紹了用Python進(jìn)行TCP網(wǎng)絡(luò)編程的教程,是Python學(xué)習(xí)當(dāng)中的基礎(chǔ)知識,代碼基于Python2.x版本,需要的朋友可以參考下2015-04-04
pandas的drop_duplicates無法去重問題解決
在我們利用Pandas進(jìn)行數(shù)據(jù)清洗的時候,往往會用到drop_duplicates()進(jìn)行去重,本文主要介紹了pandas的drop_duplicates無法去重問題解決,具有一定的參考價值,感興趣的可以了解一下2024-03-03

