用Python编程,两个乒乓球队进行比赛问题
发布网友
发布时间:2022-05-04 11:43
我来回答
共2个回答
热心网友
时间:2022-06-21 13:37
m=['a','b','c']
n=['x','y','z']
t=[]
for i in m:
for g in n:
t.append(i)
t.append(g)
if t[0]=='a' and t[1]!='x' :
print(t[0],t[1])
if t[0]=='b':
print(t[0],t[1])
if t[0]=='c'and t[1]!='x'and t[1]!='z':
print(t[0],t[1])
t=[]
热心网友
时间:2022-06-21 13:37
for player1 in 'abc':
for player2 in 'xyz':
if (player1 == 'a' and player2 != 'x') or \
(player1 == 'c' and player2 not in 'xz'):
print("{}----{}\n".format(player1, player2))
追问
可是运行出来的结果是 : a----y a----z c----y ,您能帮我解决一下吗?
追答for player1 in 'cab':
for player2 in 'xyz':
if player1 == 'c' and player2 not in 'xz':
remain2 = set('xyz') - set(player2)
print("{}----{}\n".format(player1,player2))
if player1 == 'a' and player2 != 'x' and player2 in remain2:
remain2 -= set(player2)
print("{}----{}\n".format(player1,player2))
if player1 == 'b' and player2 in remain2:
print("{}----{}\n".format(player1,player2))