這裏是我當前的代碼:打印列表水平
def print_banner(input_text, horiz_vert, letters):
'''prints string into ascii art.'''
#Prints Horizontal
if horiz_vert == "horizontal":
for i in input_text:
for j in range(6):
print(letters[i][j], end = "")
print()
#Prints Vertical
elif horiz_vert == "vertical":
for i in input_text:
for j in range(6):
print(letters[i][j])
print()
def main():
# Input text to be changed into ascii art.
input_text = input("Input your string of text here: ").lower()
# Chooses horizontal or vertical.
horiz_vert = input("Would you like horizontal or vertical? ").lower()
# Dictonary with all the accii art letters
letters = {"a": [" ___ ",
" / \ ",
" /^ \ ",
"//_\ \ ",
"/_____ \ ",
"/__/ \__\ "],
"b": [".______ ",
"| _ \ ",
"| |_) | ",
"| _ < ",
"| |_) |",
"|______/ "]}
print_banner(input_text, horiz_vert, letters)
# Calls Main
if __name__ == "__main__":
main()
目前
,如果你的INPUT_TEXT輸入「AB」,做你會得到下面的輸出垂直打印選項:
___
/ \
/^ \
//_\ \
/_____ \
/__/ \__\
.______
| _ \
| |_) |
| _ <
| |_) |
|______/
但是當你鍵入的水平我想下面的輸出:
___ .______
/ \ | _ \
/^ \ | |_) |
//_\ \ | _ <
/_____ \ | |_) |
/__/ \__\ |______/
我應該怎麼做才能廁所讓它像那樣打印?
感謝您的幫助!
主要是你要切換'i'和'j'循環,也許添加一些空間藝術的 –
工作,人。 – MohitC
如果你使每行的ASCII字母的寬度相同,這可能會有所幫助。 – mkrieger1