python列表示例

aa = ['小张', '小周', '小王', '小刘', '小李']
bb = ['小明', '小红', '小李', '小刚', '小白']
cc = ['Jack', 'Tom', 'Jim', 'Ble', 'Ala']
ops = ("显示好友", "添加好友", "删除好友", "推荐好友")


def qq(operator, nike1, nike2):
    while True:
        for i in range(len(operator)):
            print("{}--->{}".format(i+1, operator[i]))
        choice = input("请选择序号进行操作:")
        if choice == '1':
            print("你的QQ好友列表为:{}".format(nike1))
        elif choice == '2':
            friend = input("请输入好友名称:")
            nike1.append(friend)
            print("你的QQ好友列表为:{}".format(nike1))
        elif choice == '3':
            no_friend = input("请输入要删除的好友名称:")
            if no_friend in nike1:
                nike1.remove(no_friend)
            else:
                print("{}本来就不是你的好友!".format(no_friend))
            print("你的QQ好友列表为:{}".format(nike1))
        elif choice == '4':
            mixed = []
            to_add = []
            for item in nike1:
                if item in nike2:
                    mixed.append(item)
            if len(mixed) > 0:
                for f in nike2:
                    if f not in nike1:
                        to_add.append(f)
            print("为你推荐以下好友:{}".format(to_add))
        else:
            print("输入错误!")
            exit()


user = input("请选择登录的QQ昵称:")
if user == 'aa':
    qq(ops, aa, bb)
elif user == 'bb':
    qq(ops, bb, aa)
elif user == 'cc':
    qq(ops, cc, bb)
else:
    print("你输入的QQ昵称不存在!")

 

上一篇:Linux安装ElasticSearch以及Ik分词器


下一篇:2021牛客暑期多校训练营6 F. Hamburger Steak(贪心/好题)