用 *号输出字母 C的图案
方法1:
print(" ***** ") print(" ** * ") print(" ** ") print(" ** ") print(" ** * ") print(" ***** ")
方法2:
ch = [[0, 1, 1, 0], [1, 0, 0, 1], [1, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 1], [0, 1, 1, 0]] for i in range(len(ch)): for j in ch[i]: if j == 0: print(" ",end="") else: print("*", end=" ") print()
输出结果:
方法3:
from PIL import Image,ImageDraw,ImageFont import numpy as np text = "C" myfont = ImageFont.truetype("msyh.ttc", 12) # 在代码所在目录下需要放置字体文件,此处为msyh.tcc size = myfont.getsize(text) img = Image.new("1", size, "black") draw = ImageDraw.Draw(img) draw.text((0,0), text, "white", font=myfont) pixels = np.array(img, dtype=np.uint8) chars = np.array([' ', '*'], dtype="U1")[pixels] strings = chars.view('U' + str(chars.shape[1])).flatten() print(" ".join(strings))
输出结果: