某公司要从赵、钱、孙、李、周五名新毕业的大学生中选派一些人出国学习。选派必须情足以下条件?:
(1)若赵去,则钱也去.
(2)李、周两人中必有一人去.
(3)钱、孙两人中去且仅去一人.
(4)孙,李两人同去或同不去.
(5)若周去,则赵、钱也同去.
问该公司如何指派他们出国?
ls=[0,1]
''' p:赵去
q:钱去
r:孙去
s:李去
t:周去'''
for p in ls:
for q in ls:
for r in ls:
for s in ls:
for t in ls:
if ( not p or q)\
and (s or t)\
and ((q and not r) or ( not q and r))\
and ((r and s) or ( not r and not s))\
and ( not t or (p and q)):
if p==1:
print("赵去")
if q==1:
print("钱去")
if r==1:
print("孙去")
if s==1:
print("李去")
if t==1:
print("周去")
print()
直接设出原子变量后根据所给的条件筛选出符合的结果。
结果如下: