编程语言
首页 > 编程语言> > python列表示例

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昵称不存在!")

 

标签:elif,示例,python,format,列表,friend,print,nike1,好友
来源: https://www.cnblogs.com/ooops/p/15738366.html