python兩則99乘法表

來源:互聯網
上載者:User

標籤:style   print   乘法   嵌套迴圈   color   end   range   初學   nbsp   

分別應用while和for的嵌套迴圈,適用於初學的人看看

x = 1while x <= 9:    y = 1    while y <= x:        print (y,‘*‘,x,‘=‘,x*y,end="\t")        y += 1    print ("")    x += 1
執行結果:
1 * 1 = 1 
1 * 2 = 22 * 2 = 41 * 3 = 32 * 3 = 63 * 3 = 91 * 4 = 42 * 4 = 83 * 4 = 124 * 4 = 161 * 5 = 52 * 5 = 103 * 5 = 154 * 5 = 205 * 5 = 251 * 6 = 62 * 6 = 123 * 6 = 184 * 6 = 245 * 6 = 306 * 6 = 361 * 7 = 72 * 7 = 143 * 7 = 214 * 7 = 285 * 7 = 356 * 7 = 427 * 7 = 491 * 8 = 82 * 8 = 163 * 8 = 244 * 8 = 325 * 8 = 406 * 8 = 487 * 8 = 568 * 8 = 641 * 9 = 92 * 9 = 183 * 9 = 274 * 9 = 365 * 9 = 456 * 9 = 547 * 9 = 638 * 9 = 729 * 9 = 81

for i in range(1,10):    for j in range(1,1+i):        print ("%dx%d=%d\t"%(j,i,i*j),end="")    print ("")

執行結果:

1x1=11x2=22x2=41x3=32x3=63x3=91x4=42x4=83x4=124x4=161x5=52x5=103x5=154x5=205x5=251x6=62x6=123x6=184x6=245x6=306x6=361x7=72x7=143x7=214x7=285x7=356x7=427x7=491x8=82x8=163x8=244x8=325x8=406x8=487x8=568x8=641x9=92x9=183x9=274x9=365x9=456x9=547x9=638x9=729x9=81

python兩則99乘法表

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.