用Python进行判断3

某公司要从赵、钱、孙、李、周五名新毕业的大学生中选派一些人出国学习。选派必须情足以下条件?:

(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()

直接设出原子变量后根据所给的条件筛选出符合的结果。

结果如下:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值