题干:在某班班委的选举中,已知王小红,李强,丁金生三人被选入班委会,该班三名同学的预言如下:
甲:王小红为班长,李强为生活委员。
乙:丁金生为班长,王晓红为生活委员。
丙:李强为班长,王小红为学习委员。
名单公布后,发现三人都恰好猜对一半,请问三名同学各自何职?
ls = [0,1]
for p in ls:#p:王小红为班长for q in ls:#q:李强为生活委员for r in ls:#r:丁金生为班长for s in ls:#s:王小红为生活委员for t in ls:#t:李强为班长for u in ls:#u:王小红为生活委员b1 = (p == 0 and q == 1)b2 = (p == 1 and q == 0)c1 = (r == 0 and s == 1)c2 = (r == 1 and s == 0)d1 = (t == 0 and u == 1)d2 = (t == 1 and u == 1)if (b1 + c1 + d1 == 3)\or (b1 + c1 + d2 == 3)\or (b1 + c2 + d1 == 3)\or (b1 + c2 + d2 == 3)\or (b2 + c1 + d2 == 3)\or (b2 + c2 + d1 == 3)\or (b2 + c2 + d2 == 3)\or (b2 + c1 + d1 == 3):if p + s + u == 1 and q + t == 1:#王小红只能从班长、生活委员和学习委员里面选择一个职位#李强只能从生活委员和班长中选择一个职位print("p:{} q:{} r:{} s:{} t:{} u:{}".format(p,q,r,s,t,u) )