某公司要从赵钱孙李周五名新毕业的大学生中选派一些人出国留学。选派条件必须满足以下条件:
(1)若赵去,则钱也去(2)李周二人中必有一人去(3)钱孙两人中去且仅去一人(4)孙李两人同去或同不去(5)若周去,则赵钱也同去。
代码如下:
##设p为赵去,q为钱去,r为孙去,s为李去,m为周去
for p in range(2):
for q in range(2):
for r in range(2):
for s in range(2):
for m in range(2):
#if (p==q==r==s==m==0):continue
P=(not p)or q##1条件
Q=s or m ##2条件
R=(q and (not r)) or ((not q)and r)##3条件
S=(r and s)or((not r)and(not s))##4条件
M=(not m) or (p and q)##5条件
E=P and Q and R and S and M##对PQRSM合取
if E==1:
print('{},{},{},{},{}'.format(p,q,r,s,m))
运行结果: