如题:

python代码如下:
for a in range(1,5):
for b in range(0,9):
for c in range(0,9):
abc = a*100 + b*10 + c
t1 = abc % 8 == 0 #甲说abc可以被2整除3次
t2 = abc % 9 == 0 #乙说abc可以被3整除2次
t3 = abc % 7 == 0 #丙说abc可以被7整除
t4 = a + b + c == 15 #丁说abc之和是15
if t1 is True and t2 is True and t3 is True:
print ("丁说谎,abc = ", abc)
elif t1 is True and t2 is True and t4 is True:
print ("丙说谎,abc = ", abc)
elif t1 is True and t3 is True and t4 is True:
print ("乙说谎,abc = ", abc)
elif t2 is True and t3 is True and t4 is True:
print ("甲说谎,abc = ", abc)
运行程序得到结果:
乙说谎,abc = 168
通过Python代码解析,寻找符合条件的三位数abc,该数满足被2整除3次、被3整除2次及被7整除等条件,同时探讨不同条件下各变量的真伪,最终确定唯一符合要求的数字。
1060





