Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python Exercise Example 22

Python Exercise Example 22

Python 100 Examples Python 100 Examples

**Question:** Two table tennis teams compete, each with three players. Team A consists of a, b, and c; team B consists of x, y, and z. The match list has been decided by drawing lots. Someone asked the players about the match list. a said he does not play against x, and c said he does not play against x or z. Write a program to find the list of opponents for the three 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

\t

c--%s

'

%

(

chr

(

i

)

,

chr

(

j

)

,

chr

(

k

)

)

)

The output of the above example is:


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

Python 100 Examples Python 100 Examples