Python Practice Example 22

Python 100例Python 100 Examples

Title:Two table tennis teams competed against each other, each fielding three players. Team A consisted of a, b, and c; Team B consisted of x, y, and z. The match list had been decided by drawing lots. Someone asked the players about the match list. a said he would not play against x, and c said he would not play against x or z. Please write a program to find out the match list for the three pairs of players.

Program source code:

Example

#!/usr/bin/python # -*- coding: UTF-8 -*- for i in range(ord('x'),ord('z') + 1): for j in range(ord('x'),ord('z') + 1): if i != j: for k in range(ord('x'),ord('z') + 1): if (i != k) and (j != k): if (i != ord('x')) and (k != ord('x')) and (k != ord('z')): print ('order is a -- %s\t b -- %s\tc--%s' % (chr(i),chr(j),chr(k)))

The output of the above example is:

order is a -- z     b -- x    c--y

Python 100例Python 100 Examples

Other Extensions