题目:
今有物不知其数,三三数之剩二,五五数之剩三,七七数之剩二,为何?
(即:一个数除3余2,除5余3,除7余2)
具体操作:
x=int(input("请输入数字:"))
if x%3 == 2 and x%5 == 3 and x%7 == 2 :
print("输入正确")
else :
print("输入错误")
优化:
x=int(input("请输入数字:"))
if x%3 == 2:
if x%5 == 3:
if x%7 == 2:
print("输入正确")
else:
print("输入错误,满足三三数之剩二和五五数之剩三,不满足七七数之剩二")
else:
print("输入错误,满足三三数之剩二,不满足五五数之剩三")
else:
print("输入错误,不满足三三数之剩二")
结果展示:
优化: