以下是几个使用Python语言打印特殊图形的示例。
- n = 5
- for i in range(n):
- for j in range(i+1):
- print("*", end="")
- print()
输出:
- *
- **
- ***
- ****
- *****
- n = 5
- for i in range(n):
- for j in range(n):
- print("*", end="")
- print()
输出:
- *****
- *****
- *****
- *****
- *****
- n = 5
- for i in range(n):
- for j in range(i+1):
- print("*", end="")
- print()
- for i in range(n-1):
- for j in range(n-i-1):
- print("*", end="")
- print()
输出:
- *
- **
- ***
- ****
- *****
- ****
- ***
- **
- *
- n = 5
- for i in range(n):
- for j in range(n-i-1):
- print(" ", end="")
- for j in range(i+1):
- print("*", end="")
- print()
- for i in range(n-1):
- for j in range(i+1):
- print(" ", end="")
- for j in range(n-i-1):
- print("*", end="")
- print()
输出:
- *
- **
- ***
- ****
- *****
- ****
- ***
- **
- *
- import math
-
- def heart(x, y):
- if ((x*0.04)**2 + (y*0.04)**2 - 1)**3 - (x*0.04)**2 * (y*0.04)**3 <= 0:
- return "*"
- else:
- return " "
-
- n = 20
- for i in range(-n, n):
- for j in range(-n, n):
- print(heart(j, i), end="")
- print()
输出:
-
- *** ***
- ** ** ** **
- ** ** ** **
- * * *
- * *
- * *
- * *
- * *
- * *
- * *
- ** **
- ** **
- *** ***
- ** **
- ** **
8.特殊形状
- ""
- a = 176
- b = 219
- print(chr(b),chr(a),chr(a),chr(a),chr(b))
- print(chr(a),chr(b),chr(a),chr(b),chr(a))
- print(chr(a),chr(a),chr(b),chr(a),chr(a))
- print(chr(a),chr(b),chr(a),chr(b),chr(a))
- print(chr(b),chr(a),chr(a),chr(a),chr(b))
-
-
- ""