2 回答

TA貢獻1752條經驗 獲得超4個贊
要將 ASCII 字母一個一個地打印出來,您必須將字母分成多行并連接所有相應的行。假設您的 ASCII 文本由 8 行組成:
name = input("What is your name: ")
splitname = list(name)
# Put the right number of lines of the ASCII letter
letter_height = 8
# This will contain the new lines
# obtained concatenating the lines
# of the single letters
complete_lines = [""] * letter_height
for i in range(len(splitname)):
f = open(splitname[i] + ".txt","r")
contents = f.read()
# Split the letter in lines
lines = contents.splitlines()
# Concatenate the lines
for j in range(letter_height):
complete_lines[j] = complete_lines[j] + " " + lines[j]
# Print all the lines
for j in range(letter_height):
print(complete_lines[j])

TA貢獻1876條經驗 獲得超7個贊
解決方案有點復雜,因為您必須逐行打印出來,但您已經需要“信件”文件的所有內容。
解決方案是讀取第一個字母的第一行,然后將此字符串與下一個字母的第一行連接起來,依此類推。然后對第二行執(zhí)行相同的操作,直到打印所有行。
我不會提供完整的解決方案,但我可以幫助修復您的代碼。首先,您只需閱讀信件文件的一行。如果句柄仍處于打開狀態(tài),您可以使用f.readline()
而不是f.read()
每次連續(xù)調用此函數(shù)將讀取此文件中的下一行。
添加回答
舉報