简体   繁体   中英

Input from user is an list I made. Now how do I read it?

Basicly I've been trying to make this word generator, which displays your input in a big font in the console. I'm trying to take the user's input, then put each char individually in a list. So now the first item in the list is 'a' for example (with the input being 'apple' for example). Now there's a list I made called a. I want to print that list by the user's input (a). How do I do so? This is my code:

a = ["@@@@@",
    ("@   @"),
    ("@   @"),
    ("@@@@@"),
    ("@   @"),
    ("@   @"),
    ("@   @")]

b = ["@@@@ ",
    ("@   @"),
    ("@   @"),
    ("@@@@ "),
    ("@   @"),
    ("@   @"),
    ("@@@@ ")]

c = ["@@@@@",
    ("@    "),
    ("@    "),
    ("@    "),
    ("@    "),
    ("@    "),
    ("@@@@@")]

d = ["@@@@ ",
    ("@   @"),
    ("@   @"),
    ("@   @"),
    ("@   @"),
    ("@   @"),
    ("@@@@ ")]

e = ["@@@@@",
    ("@    "),
    ("@    "),
    ("@@@@@"),
    ("@    "),
    ("@    "),
    ("@@@@@")]

f = ["@@@@@",
    ("@    "),
    ("@    "),
    ("@@@@@"),
    ("@    "),
    ("@    "),
    ("@    ")]

g = ["@@@@@",
    ("@    "),
    ("@    "),
    ("@ @@@"),
    ("@   @"),
    ("@   @"),
    ("@@@@@")]

h = ["@   @",
    ("@   @"),
    ("@   @"),
    ("@@@@@"),
    ("@   @"),
    ("@   @"),
    ("@   @")]

i = ["@@@@@",
    ("  @  "),
    ("  @  "),
    ("  @  "),
    ("  @  "),
    ("  @  "),
    ("@@@@@")]

j = ["    @",
    ("    @"),
    ("    @"),
    ("    @"),
    ("    @"),
    ("@   @"),
    (" @@@ ")]    

k = ["@   @",
    ("@  @ "),
    ("@ @  "),
    ("@@   "),
    ("@ @  "),
    ("@  @ "),
    ("@   @")]

l = ["@    ",
    ("@    "),
    ("@    "),
    ("@    "),
    ("@    "),
    ("@    "),
    ("@@@@@")]  

m = ["@   @",
    ("@@ @@"),
    ("@ @ @"),
    ("@ @ @"),
    ("@   @"),
    ("@   @"),
    ("@   @")]

word = []
input_word = input("Which word would you like to display?")
for i in input_word:
  word.append(i)

Create a dictionary that maps each letter to the corresponding list:

letter_map = {'a': a, 'b': b, 'c': c, ...}
in = input("What letter?")
print(letter_map[in[0]])

word contains the word

  1. make it a dictionary where the letter is the key and the values are in an array: letters = {'a': ["@@@@@", "@ @", "@ @", "@@@@@", "@ @", "@ @", "@ @"], ...}
  2. iterate over the count of items in the array with range(7) using for : for row in range(7):
  3. iterate over the word letters, getting the mapped symbols: for letter in word:
  4. join with a space: outword += " " + letters[letter][row]
  5. finally join all lines with a newline

That should get you started. Feel free to try and post your results. We can help you once you have some code.

  1. (optional) learn list comprehensions and come up with a one-liner for some unreadable fun

print('\\n'.join([' '.join([{'a': ["@@@@@", "@ @", "@ @", "@@@@@", "@ @", "@ @", "@ @"] , 'b': ["@@@@ ", "@ @", "@ @", "@@@@ ", "@ @", "@ @", "@@@@ "] , 'c': ["@@@@@", "@ ", "@ ", "@ ", "@ ", "@ ", "@@@@@"] , 'd': ["@@@@ ", "@ @", "@ @", "@ @", "@ @", "@ @", "@@@@ "] , 'e': ["@@@@@", "@ ", "@ ", "@@@@@", "@ ", "@ ", "@@@@@"] , 'f': ["@@@@@", "@ ", "@ ", "@@@@@", "@ ", "@ ", "@ "] , 'g': ["@@@@@", "@ ", "@ ", "@ @@@", "@ @", "@ @", "@@@@@"] , 'h': ["@ @", "@ @", "@ @", "@@@@@", "@ @", "@ @", "@ @"] , 'i': ["@@@@@", " @ ", " @ ", " @ ", " @ ", " @ ", "@@@@@"] , 'j': [" @", " @", " @", " @", " @", "@ @", " @@@ "] , 'k': ["@ @", "@ @ ", "@ @ ", "@@ ", "@ @ ", "@ @ ", "@ @"] , 'l': ["@ ", "@ ", "@ ", "@ ", "@ ", "@ ", "@@@@@"] , 'm': ["@ @", "@@ @@", "@ @ @", "@ @ @", "@ @", "@ @", "@ @"]}[l][i] for l in "abcdefghijklm"]) for i in range(7)]))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM