有时候,话可以反着理解
A、B、C、D、E参加竞赛,根据下列条件哪些人参加了竞赛:
1、A参加时B也参加;
2、B和C只有一个参加;
3、C和D或都参加或都不参加。
4、D和E至少有一个人参加;
5、如果E参加,那么A和D都参加。
data = ["A", "B", "C", "D", "E"]
for a in [0, 1]:
for b in [0, 1]:
for c in [0, 1]:
for d in [0, 1]:
for e in [0, 1]:
if a == 1 and b != 1:
continue
if (b == 1 and c == 1) or (b == 0 and c == 0):
continue
if (c == 1 and d == 0) or (c == 0 and d == 1):
continue
if d == 0 and e == 0:
continue
if e == 1 and (a == 0 or d == 0):
continue
result = [a, b, c, d, e]
for da, re in zip(data, result):
if re == 0:
continue
print(da, end=" ")
print()
D:\Python\Python38\python.exe D:/Python/study/20210722.py
C D
Process finished with exit code 0