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

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

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

本文實例為大家分享了python列表使用實現(xiàn)名字管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下

實現(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,要轉換為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中列表實現(xiàn)名字管理系統(tǒng)的代碼:

1、打印功能提示
2、獲取用戶輸入
3、根據(jù)用戶的輸入選擇相應的功能進行實現(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:"))
#功能實現(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)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

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

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

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

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

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

    Flask WTForms 表單插件的使用

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

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

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

    python基礎之多態(tài)

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

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

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

    python計算日期之間的放假日期

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

    Python中計算相似度的方法詳解

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

    Pandas.DataFrame轉置的實現(xiàn)

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

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

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

最新評論

皋兰县| 潮州市| 奇台县| 华坪县| 东丰县| 宜丰县| 田东县| 柳州市| 勃利县| 阿拉善右旗| 龙井市| 溧阳市| 新巴尔虎左旗| 突泉县| 大安市| 杨浦区| 平山县| 林周县| 永安市| 洪雅县| 岑溪市| 汉中市| 北安市| 巩义市| 田东县| 陆川县| 安阳县| 弥勒县| 和政县| 蒲城县| 阿克陶县| 广昌县| 宿松县| 东乌珠穆沁旗| 长岛县| 六枝特区| 台南县| 拉萨市| 商洛市| 云梦县| 焦作市|