打印10以内偶数乘积的列表python_将列表中的所有偶数打印到给定的数字
我剛剛開始涉足Python,并且已經(jīng)開始瀏覽learnpython.org上的章節(jié)。在“循環(huán)”一章中,我用下面的代碼解決了這個問題。但是我不確定它是否是最有效的。當(dāng)然,這似乎不是因為我必須定義兩次“不能超過的數(shù)字”。在這個(我猜)容易出問題的時候,干的應(yīng)該可以堅持,對吧?Loop through and print out all even numbers from the numbers list in
the same order they are received. Don't print any numbers that come
after 237 in the sequence.
我的代碼:numbers = [ 951, 402, 984, 651, 360, 69, 408, 319, 601, 485, 980, 507, 725, 547, 544, 615, 83, 165, 141, 501, 263, 617, 865, 575, 219, 390, 984, 592, 236, 105, 942, 941, 386, 462, 47, 418, 907, 344, 236, 375, 823, 566, 597, 978, 328, 615, 953, 345, 399, 162, 758, 219, 918, 237, 412, 566, 826, 248, 866, 950, 626, 949, 687, 217, 815, 67, 104, 58, 512, 24, 892, 894, 767, 553, 81, 379, 843, 831, 445, 742, 717, 958, 609, 842, 451, 688, 753, 854, 685, 93, 857, 440, 380, 126, 721, 328, 753, 470, 743, 527 ]
# My Solution
for x in numbers:
if x != 237:
if x % 2 == 0:
print x
if x == 237:
break
總結(jié)
以上是生活随笔為你收集整理的打印10以内偶数乘积的列表python_将列表中的所有偶数打印到给定的数字的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: pip安装deb_趟坑:使用pip安装T
- 下一篇: 宁德时代与特斯拉签订协议 电池巨头又