ASCII空格和字符删除

时间:2015-09-05 19:10:20

标签: python python-3.x fonts io ascii

我必须编写一个程序,它接受三个输入并使用它们来确定如何显示由文本文件定义的ASCII字艺术字体。我得到的输出几乎是正确的,但我的程序错误地处理空间完全省略了像HOW DO这样的东西。 这是我的代码:

hi = input('Height: ')
wi = input('Width: ')
tx = input('Text: ')
hi = int(hi)
output = [[] for _ in range(hi)]
with open("font.txt") as fi:
  lines = fi.readlines()

for character in tx:
  offset = int(cd[character])
  start = offset * hi
  end = start + hi 
  letter = lines[start:end] 
  for outputline, letterline in zip(output, letter):
      outputline.append(letterline.rstrip('\n'))
for line in output:
  print(''.join(line))

我的输出

Height: 8
Width: 9
Text: APPLE STORES ARE BAD FOR YOUR HEALTH
 _______  _______  _______  _        _______  _______ _________ _______  _______  _______  _______  _______  _______  _______  ______   _______  ______   _______  _______  _______           _______           _______           _______  _______  _       _________         
(  ___  )(  ____ )(  ____ )( \      (  ____ \(  ____ \\__   __/(  ___  )(  ____ )(  ____ \(  ____ \(  ___  )(  ____ )(  ____ \(  ___ \ (  ___  )(  __  \ (  ____ \(  ___  )(  ____ )|\     /|(  ___  )|\     /|(  ____ )|\     /|(  ____ \(  ___  )( \      \__   __/|\     /|
| (   ) || (    )|| (    )|| (      | (    \/| (    \/   ) (   | (   ) || (    )|| (    \/| (    \/| (   ) || (    )|| (    \/| (   ) )| (   ) || (  \  )| (    \/| (   ) || (    )|( \   / )| (   ) || )   ( || (    )|| )   ( || (    \/| (   ) || (         ) (   | )   ( |
| (___) || (____)|| (____)|| |      | (__    | (_____    | |   | |   | || (____)|| (__    | (_____ | (___) || (____)|| (__    | (__/ / | (___) || |   ) || (__    | |   | || (____)| \ (_) / | |   | || |   | || (____)|| (___) || (__    | (___) || |         | |   | (___) |
|  ___  ||  _____)|  _____)| |      |  __)   (_____  )   | |   | |   | ||     __)|  __)   (_____  )|  ___  ||     __)|  __)   |  __ (  |  ___  || |   | ||  __)   | |   | ||     __)  \   /  | |   | || |   | ||     __)|  ___  ||  __)   |  ___  || |         | |   |  ___  |
| (   ) || (      | (      | |      | (            ) |   | |   | |   | || (\ (   | (            ) || (   ) || (\ (   | (      | (  \ \ | (   ) || |   ) || (      | |   | || (\ (      ) (   | |   | || |   | || (\ (   | (   ) || (      | (   ) || |         | |   | (   ) |
| )   ( || )      | )      | (____/\| (____/\/\____) |   | |   | (___) || ) \ \__| (____/\/\____) || )   ( || ) \ \__| (____/\| )___) )| )   ( || (__/  )| )      | (___) || ) \ \__   | |   | (___) || (___) || ) \ \__| )   ( || (____/\| )   ( || (____/\   | |   | )   ( |
|/     \||/       |/       (_______/(_______/\_______)   )_(   (_______)|/   \__/(_______/\_______)|/     \||/   \__/(_______/|/ \___/ |/     \|(______/ |/       (_______)|/   \__/   \_/   (_______)(_______)|/   \__/|/     \|(_______/|/     \|(_______/   )_(   |/     \|

请注意不显示空格(应与其他字符的大小相同)。

1 个答案:

答案 0 :(得分:0)

对于那些仍在寻找解决方案的人:

for character in tx:
  offset = int(cd[character])
  start = offset * hi
  end = start + hi
  if character == ' ':
    lines[start:end] = [' ' * int(wi) for _ in range(int(hi))]
  letter = lines[start:end]