【发布时间】:2021-01-31 14:21:28
【问题描述】:
我想使用“*”或任何其他给定的特殊字符(例如点阵打印机的工作原理)打印任何英文字母。
我可以想出一个函数def printLetters(string, font_size, special_char):,当它与任何字母一起传递时,会使用指定的特殊字符打印该字母。
考虑字母“A”:
def printLetters('A', 10, '&'): # would print the letter A within a 10x10 matrix using '&'
&&&&&&&&
& &
& &
& &
&&&&&&&&&&
& &
& &
& &
& &
& &
以及每个字符的此类代码 sn-ps。 'A' 示例:
FUNCTION_TO_PRINT_A:
space = ' '
#print first line
print('', special_char*(font_size-2))
for i in range(1, font_size-1):
#print(i)
if font_size//2 == i:
print(special_char*(font_size))
print(special_char, space*(font_size-2), special_char, sep = '')
printLetters('A', 10, "&")
但是当参数string 有多个字符时,它会在第一个字符后打印乱码。
所以我只是想要一些想法/code-sn-ps,它会首先打印string 中所有字符的第一行,依此类推直到最后一行,以便所有这些 characters 并排排列水平放置在控制台上。
【问题讨论】:
标签: python-3.x design-patterns dot-matrix