寫一個程序,打印出0-100所有奇數
ls = range(0, 101)
for i in ls:
if i % 2 == 1:
print(i)
--------------------------------
愛因斯坦曾出過這樣一道有趣的數學題:有一個長階梯,走每步上2階,最后剩余1階;如果每步上3階,最后剩2階;若每步上5階,最后剩4階;若每步上6階,最后剩5階,
只有每步上7階,最后剛好一階不剩。
-編寫程序求該階梯至少有多少階
x = 10
while x < 1000:
if (x % 2 == 1) and (x % 3 == 2) and (x % 5 == 4) and (x % 6 == 5) and (x % 7 ==0):
print(x)
x += 1
#break;
else:
x += 1
print("循環結束")
--------------------------------------
x = 10
while x < 1000:
if (x % 2 == 1) \
and (x % 3 == 2) \
and (x % 5 == 4) \
and (x % 6 == 5) \
and (x % 7 ==0):
print(x)
x += 1
#break;
else:
x += 1
print("循環結束")
-------------------------------------------