python九九乘法表和列印圖形程式

來源:互聯網
上載者:User

標籤:python   乘法表   

一、列印九九乘法表:

#coding:utf-8for i in range(1,10):    for j in range(1,i+1):        print("%dx%d=%d") %(j,i,j*i),    print ‘\n‘

結果:

650) this.width=650;" title="99.png" alt="wKiom1lLma-Trl7_AAASsxiCmSs619.png-wh_50" src="https://s1.51cto.com/wyfs02/M02/99/BB/wKiom1lLma-Trl7_AAASsxiCmSs619.png-wh_500x0-wm_3-wmp_4-s_2116397384.png" />

二、列印正方形

實體正方形 代碼:

#coding:utf-8rows=int(raw_input("輸入正方形邊長:"))for i in range(rows):    for j in range(rows):        print("*"),    print

650) this.width=650;" title="11.png" alt="wKiom1lLmjOB5V6CAAAD1-Cabjk846.png-wh_50" src="https://s5.51cto.com/wyfs02/M02/99/BB/wKiom1lLmjOB5V6CAAAD1-Cabjk846.png-wh_500x0-wm_3-wmp_4-s_1253390052.png" />

空心正方形 代碼:

#coding:utf-8rows=int(raw_input("輸入正方形邊長:"))for x in range(rows):    for y in range(rows):        if x !=0 and x != rows-1:            if y==0 or y == rows-1:                print(" * "),            else:                print("   "),        else:             print(" * "),    print("\n")

效果:

650) this.width=650;" title="22.png" alt="wKioL1lLmoWSH8xxAAAHnVE_ymM763.png-wh_50" src="https://s1.51cto.com/wyfs02/M00/99/BB/wKioL1lLmoWSH8xxAAAHnVE_ymM763.png-wh_500x0-wm_3-wmp_4-s_3653282803.png" />


三、列印聖誕樹

代碼:

#coding:utf-8rows=3for x in range(rows):    for i in range(1,13):        if i % 2 ==0:            continue        else:            print(str(i * ‘*‘).center(11))for y in range(10):    print(‘*‘.center(11))

效果:

650) this.width=650;" title="333.png" alt="wKioL1lLmuDwveUfAAAIH4QbHJ0392.png-wh_50" src="https://s2.51cto.com/wyfs02/M01/99/BB/wKioL1lLmuDwveUfAAAIH4QbHJ0392.png-wh_500x0-wm_3-wmp_4-s_275057874.png" />

四、列印淩形

代碼:

#coding:utf-8rows=10#while True:for i in range(1, rows):    if i % 2 == 0:        continue    else:        print(str(i * ‘*‘).center(rows))for i in range(rows):    if i % 2 == 0:        continue    else:        print(str((rows - i) * ‘*‘).center(rows))

效果:



650) this.width=650;" title="88.png" alt="wKiom1lLm-ahewALAAADRywHOoo780.png-wh_50" src="https://s4.51cto.com/wyfs02/M00/99/BB/wKiom1lLm-ahewALAAADRywHOoo780.png-wh_500x0-wm_3-wmp_4-s_3866568092.png" />


寫簡單,如有更好的,請指正並交流~

本文出自 “學地止境” 部落格,請務必保留此出處http://dyc2005.blog.51cto.com/270872/1941069

python九九乘法表和列印圖形程式

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.