Python basic algorithm collection (17)-the list of three table tennis teams

'''
两个乒乓球队进行比赛,各出三人。甲队为a,b,c三人,乙队为x,y,z三人。
已抽签决定比赛名单。有人向队员打听比赛的名单。a说他不和x比,c说他不和x,z比。
请编程序找出三队赛手的名单。
用的是列表
'''
L1 = ['x', 'y', 'z']#
for a in L1:
    for b in L1:
        # 避免重复参赛
        if a != b:
            for c in L1:
                # 避免重复参赛
                if a != c and b != c:
                    # 根据题意判断
                    if a != 'x' and c != 'x' and c != 'z':
                        print('a的对手是%s\nb的对手是%s\nc的对手是%s' % (a, b, c))

 

Guess you like

Origin blog.csdn.net/weixin_43115314/article/details/114390982