python 今有物不知其数!

除三余二 除五余三 除七余二,问几何?

#方法一

1
none = True 2 i = 0 3 while none: 4 i +=1 5 if i%3 == 2 and i%5 == 3 and i%7 == 2: 6 print(i) 7 none = False

 

1 #方法二
2 
3 i = 0
4 while True:
5     i +=1
6     if i%3 == 2 and i%5 == 3 and i%7 == 2:
7         print(i)
8         break

补,1000以内有哪些数字满足条件

1 for i in range(1000):
2     if i % 3 == 2 and i % 5 == 3 and i % 7 == 2:
3         print(i)
4     else:
5         continue

结果:

23
128
233
338
443
548
653
758
863
968

 

posted @ 2019-08-27 15:00  晓亮86  阅读(3155)  评论(0编辑  收藏  举报