Ashleigh Woodard
Ashleigh Woodard

Reputation: 3

Computer Science Ascii Art

So for my code I created ASCII art that can be printed vertical. Well now I want to make it print horizontal however it is not going the way I want it. How do I make my ASCII art go horizontal? Also, what do I need to know in order for the user to input a word they want and that certain word is what will be printed out in the ASCII art form?

    def print_banner(banner_str):
    horv = input("Is the banner horizontal or vertical? Respond with H or V: ")
    if horv == "V":
        for letter in banner_str:
            for string in Alphabet[letter]:
                print(string,)            
    else:
        for letter in banner_str:
            for string in Alphabet[letter]:
                print(string)

    Alphabet = {"A": ["###","# #","###","# #","# #"],
                "B": ["#  ","#  ","###","# #","###"],
                "C": ["###","#  ","#  ","#  ","###"],
                "D": ["  #","  #","###","# #","###"],
                "E": ["###","#  ","## ","#  ","###"],
                "F": ["###","#  ","## ","#  ","#  "],
                "G": ["###","# #","###","  #","###"],
                "H": ["# #","# #","###","# #","# #"],
                "I": ["###"," # "," # "," # ","###"],
                "J": ["####","  # ","  # ","# # ","### "],
                "K": ["#  #","# # ","##  ","# # ","#  #"],
                "L": ["#  ","#  ","#  ","#  ","###"],
                "M": ["#  #","## ##","# # #","#    #","#    "],
                "N": ["#   #","##  #","# # #","#  ##","#   #"],
                "O": ["###","# #","# #","# #","###"],
                "P": ["###","# #","###","#  ","#  "],
                "Q": ["###","# #","###","  #","  #"],
                "R": ["### ","#  #","### ","# # ","#  #"],
                "S": ["###","#  ","###","  #","###"],
                "T": ["###"," # "," # "," # "," # "],
                "U": ["# #","# #","# #","# #","###"],
                "V": ["# #","# #","# #","# #"," # "],
                "W": ["#   #","#   #","# # #","## ##","#   #"],
                "X": ["#   #"," # # ","  #  "," # # ","#   #"],
                "Y": ["#   #"," # # ","  #  ","  #  ","  #  "],
                "Z": ["#####","   # ","  #  "," #   ","#####"]}

    print_banner(Alphabet)

Upvotes: 0

Views: 987

Answers (1)

ZdaR
ZdaR

Reputation: 22964

def print_banner(banner_str):
    horv = raw_input("Is the banner horizontal or vertical? Respond with H or V: ")
    if (horv == "V") or (horv == "v"):
        for letter in banner_str:
            for string in Alphabet[letter]:
                print(string,)
            print 
    elif (horv =="H") or (horv == "h"):
        for i in xrange(5):
            for j in sorted(banner_str.keys())[:7]:
                print banner_str[j][i]+"\t",
            print
    else:
        print "Sorry, This was not a valid input."

Alphabet = {"A": ["###","# #","###","# #","# #"],
            "B": ["#  ","#  ","###","# #","###"],
            "C": ["###","#  ","#  ","#  ","###"],
            "D": ["  #","  #","###","# #","###"],
            "E": ["###","#  ","## ","#  ","###"],
            "F": ["###","#  ","## ","#  ","#  "],
            "G": ["###","# #","###","  #","###"],
            "H": ["# #","# #","###","# #","# #"],
            "I": ["###"," # "," # "," # ","###"],
            "J": ["####","  # ","  # ","# # ","### "],
            "K": ["#  #","# # ","##  ","# # ","#  #"],
            "L": ["#  ","#  ","#  ","#  ","###"],
            "M": ["#  #","## ##","# # #","#    #","#    "],
            "N": ["#   #","##  #","# # #","#  ##","#   #"],
            "O": ["###","# #","# #","# #","###"],
            "P": ["###","# #","###","#  ","#  "],
            "Q": ["###","# #","###","  #","  #"],
            "R": ["### ","#  #","### ","# # ","#  #"],
            "S": ["###","#  ","###","  #","###"],
            "T": ["###"," # "," # "," # "," # "],
            "U": ["# #","# #","# #","# #","###"],
            "V": ["# #","# #","# #","# #"," # "],
            "W": ["#   #","#   #","# # #","## ##","#   #"],
            "X": ["#   #"," # # ","  #  "," # # ","#   #"],
            "Y": ["#   #"," # # ","  #  ","  #  ","  #  "],
            "Z": ["#####","   # ","  #  "," #   ","#####"]}

print_banner(Alphabet)

For printing the alphabets horizontally, we need to know the length of characters to be printed as the length in this case is constant that is 5 so we iterate 5 times to print each line, and in each line we need to print the specific elements of each character. I have limited the characters to be printed as 7 (banner_str.keys())[:7] but you can change it as per requirement also note that printing all letters may produce garbage output depending on the interpreter you are using.

Upvotes: 1

Related Questions