创建一个名为用户输入Python的数组,然后用nam

2024-05-14 00:53:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图让它,这样用户可以创建文本艺术和名称,然后他们喜欢,然后当他们进入艺术名单上,他们可以看到他们的艺术名称,并显示它。现在我有了这个:

#
#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()

这可以创造多个艺术精品,但我只有这样,然后我在艺术类型: [['Cat1', 'Cat2', 'end']] 名称不显示键入Cat只会出错。你知道吗

希望你能帮忙。你知道吗


Tags: 名称trueinputifvars艺术stopprint
1条回答
网友
1楼 · 发布于 2024-05-14 00:53:54

您可以在Python dict中存储所有艺术,将每个“图像”(ASCII艺术字符串)与一个名称相关联。你知道吗

示例:

art = {}

# ...

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

while stop == False :

# ...

art[x].append(inputln)

相关问题 更多 >