最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python列表使用實(shí)現(xiàn)名字管理系統(tǒng)

 更新時(shí)間:2019年01月30日 14:28:25   作者:mico_cmm  
這篇文章主要為大家詳細(xì)介紹了python列表使用實(shí)現(xiàn)名字管理系統(tǒng),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(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("輸入錯(cuò)誤!")


小編再為大家分享另一段用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í)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • python處理json數(shù)據(jù)中的中文

    python處理json數(shù)據(jù)中的中文

    這篇文章主要介紹了python處理json數(shù)據(jù)中的中文問題,需要的朋友可以參考下
    2014-03-03
  • python 將對象設(shè)置為可迭代的兩種實(shí)現(xiàn)方法

    python 將對象設(shè)置為可迭代的兩種實(shí)現(xiàn)方法

    今天小編就為大家分享一篇python 將對象設(shè)置為可迭代的兩種實(shí)現(xiàn)方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-01-01
  • Flask WTForms 表單插件的使用

    Flask WTForms 表單插件的使用

    本文主要介紹了Flask WTForms表單插件的使用,Python的WTForms庫通過提供表單的結(jié)構(gòu)、驗(yàn)證和渲染等功能,簡化了表單的處理流程,感興趣的可以了解一下
    2023-11-11
  • Python+Tkinter繪制一個(gè)數(shù)字時(shí)鐘

    Python+Tkinter繪制一個(gè)數(shù)字時(shí)鐘

    這篇文章主要為大家詳細(xì)介紹了Python使用Tkinter繪制一個(gè)數(shù)字時(shí)鐘,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-01-01
  • python基礎(chǔ)之多態(tài)

    python基礎(chǔ)之多態(tài)

    這篇文章主要介紹了python多態(tài),實(shí)例分析了Python中返回一個(gè)返回值與多個(gè)返回值的方法,需要的朋友可以參考下
    2021-10-10
  • python判斷完全平方數(shù)的方法

    python判斷完全平方數(shù)的方法

    今天小編就為大家分享一篇python判斷完全平方數(shù)的方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-11-11
  • python計(jì)算日期之間的放假日期

    python計(jì)算日期之間的放假日期

    這篇文章主要為大家詳細(xì)介紹了python計(jì)算日期之間的放假日期,實(shí)現(xiàn)自動查詢節(jié)日,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-06-06
  • Python中計(jì)算相似度的方法詳解

    Python中計(jì)算相似度的方法詳解

    計(jì)算相似度是許多機(jī)器學(xué)習(xí)和數(shù)據(jù)分析任務(wù)中的重要步驟,尤其是在推薦系統(tǒng)、文本分析和圖像處理等領(lǐng)域,下面我們就來看看具體的實(shí)現(xiàn)方法吧
    2025-02-02
  • Pandas.DataFrame轉(zhuǎn)置的實(shí)現(xiàn)

    Pandas.DataFrame轉(zhuǎn)置的實(shí)現(xiàn)

    這篇文章主要介紹了Pandas.DataFrame轉(zhuǎn)置的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-03-03
  • python編程Flask框架簡單使用教程

    python編程Flask框架簡單使用教程

    這篇文章主要為大家介紹了python編程中Flask框架簡單使用教程,有需要的朋友可以借鑒參考下希望能夠有所幫助,祝大家多多進(jìn)步早日升職加薪
    2021-11-11

最新評論

乌兰县| 玛纳斯县| 香格里拉县| 芜湖县| 韩城市| 娱乐| 区。| 南城县| 邵武市| 巩留县| 隆尧县| 项城市| 手游| 秭归县| 韩城市| 长子县| 临朐县| 金塔县| 成安县| 烟台市| 高陵县| 霍邱县| 漳州市| 平乐县| 临西县| 元氏县| 鄂尔多斯市| 平凉市| 安多县| 镇江市| 梅州市| 简阳市| 瑞丽市| 湘西| 凤冈县| 南陵县| 抚顺县| 乐陵市| 会昌县| 津市市| 杭锦后旗|