用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")
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值