程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

python 圖形打印

編輯:Python

1.直角三角形

a = int(input('請輸入打印行數:'))
for i in range(1,a+1):
for j in range(i):
print(end='*')
print()

2.等腰三角形

a = int(input('請輸入打印行數:'))
for i in range(1,a+1):
for j in range(a+1-i):
print(end=' ')
for k in range(2*i-1):
print(end='*')
print()

3.倒三角形

a = int(input('請輸入打印行數:'))
for i in range(a):
for j in range(i):
print(end=' ')
for k in range(2*(a-i)-1):
print(end='*')
print()

4.菱形

a = int(input('請輸入打印行數:'))
for i in range(1,a//2+1):
for k in range(a//2+1-i):
print(end=' ')
for j in range(2*i-1):
print('*',end='')
print()
for i in range(a//2+1):
for k in range(i):
print(end=' ')
for j in range(a-2*i):
print('*',end='')
print()

5.平行四邊形

a = int(input('請輸入打印行數:'))
for i in range(a):
for j in range(a-i):
print(end=' ')
for k in range(a):
print(end='*')
print()

6.空心菱形

a = int(input('請輸入打印行數:'))
for i in range(1,a+1):
for j in range(a+1-i):
print(end=' ')
for k in range(2*i-1):
if i == 1 or k == 0 or k== 2*i-2:
print(end='*')
else:
print(end=' ')
print()
for i in range(1,a+1):
for j in range(i):
print(end=' ')
for k in range(2*(a-i)):
if k == 1 or k== 2*(a-i)-1:
print(end='*')
else:
print(end=' ')
print()

7.十字菱形

a = int(input('請輸入打印行數:'))
for i in range(1,a+1):
for j in range(a+1-i):
print(end=' ')
for k in range(2*i-1):
if i == 1 or k == 0 or k== 2*i-2 or i ==a or k ==i-1:
print(end='*')
else:
print(end=' ')
print()
for i in range(1,a+1):
for j in range(i):
print(end=' ')
for k in range(2*(a-i)):
if k == 1 or k== 2*(a-i)-1 or k == a-i:
print(end='*')
else:
print(end=' ')
print()

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved