简体   繁体   中英

Creating an array with its name as a user input Python then displaying it with the name

I am trying to make it so users can create text art and name then to their liking and then when they go onto the Art list they can see their art's name and show it. At the moment I have this:

#
#Text Art Thing
#15/05/2015
#By Dom

while True:
    UserInput = input("##################################################\n1 -       Create new art\n2 - Manage saved art\n3 - Watch a slideshow of all the     art\n##################################################\n\n")

    Art = []

    def NewArt():
        stop = False
        x = input("What would you like to call your art?  ")
        vars()[x] = []
        ln = 1
        while stop == False :
            inputln = input("" + str(ln) + ")  ")
            if inputln == "end" :
                stop = True
                print("You have exited the editor. Your art is shown below!\n##################################################\n")
                print("\n".join(vars()[x]))
                print("\n##################################################\n")
                Art.append(vars()[x])
            ln += 1
            vars()[x].append(inputln)





    if UserInput == "1" :
        print("Loading...")
        NewArt()
    if UserInput == "2" :
        print("Loading...")
        SavedArt()
    if UserInput == "3" :
        print("Loading...")
        SlideArt()

This can create multiple art fine but I only get this then I type in art: [['Cat1', 'Cat2', 'end']] The name does not show typing Cat only gets a error.

Hope you can help.

You can store all art in a Python dict, relating each "image" (ASCII art string) to a name.

Example:

art = {}

# ...

x = input("What would you like to call your art?  ")
art[x] = []

while stop == False :

# ...

art[x].append(inputln)

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