写一个程序,打印出0-100所有奇数
ls = range(0,101)
for i in ls:
if i % 2 == 1:
print(i)
1
3
5
7
9
11
13
15
17
19
21
23
25
27
29
31
33
35
37
39
41
43
45
47
49
51
53
55
57
59
61
63
65
67
69
71
73
75
77
79
81
83
85
87
89
91
93
95
97
99
爱因斯坦曾经出过这样一道有趣的数学题:有一个长阶梯,若每步上2阶,最后剩1阶;若每步上3阶,最后剩2阶;若每步上5阶,最后剩4阶;若每步上6阶,最后剩5阶,只有每步上7阶,最后刚好一阶不剩
- 编写程序求该阶梯至少有多少阶
x = 0
while x < 1000:
if (x % 2 == 1) \
and (x % 3 == 2) \
and (x % 5 == 4) \
and (x % 6 == 5) \
and (x % 6 == 5) \
and (x % 7 == 0):
print(x)
x += 1
# break
else:
x += 1
print("循环结束")
119
329
539
749
959
循环结束
正文完