我用python制作动画工作室/观众

时间:2014-04-24 02:15:59

标签: python python-2.7 animation

好的,所以我喜欢制作你喜欢的动画内容可以内置动画或制作你自己的动画,这是迄今为止的代码:

import time
def bi2():
    print """\ \ \    """
    time.sleep(.5)
    print """ \ \ \     """
    time.sleep(.5)
    print """  \ \ \   """
    time.sleep(.5)
    print """   \ \/   """
    time.sleep(.5)
    print """    \/\   """
    time.sleep(.5)
    print """    /\/   """
    time.sleep(.5)
    print """   / /\       """
    time.sleep(.5)
    print """  / / /     """
    time.sleep(.5)
    print """ / / /      """
    time.sleep(.5)
    proceed1234 = raw_input("| | |")
    if proceed1234 == "q":
        main_menu()
    elif proceed1234 == "b":
        animations1()
    else:
        time.sleep(.5)
        bi2()
def play2():#2nd built in
    print "Type in 'q' at any time possible to return to the main menu, or 'b' to go to     the animations menu."
    bi2()
def bi1():
    print "    |   "
    time.sleep(.5)
    print "    |"
    time.sleep(.5)
    print """   /\"""
    time.sleep(.5)
    print '''  /  \'''
    time.sleep(.5)
    print " | OO |"
    time.sleep(.5)
    print '''  \  /'''
    time.sleep(.5)
    print '''   \/'''
    time.sleep(.5)
    print "    |"
    proceed123 = raw_input("    |")
    if proceed123 == "q":
        main_menu()
    elif proceed123 == "b":
        animations1()
else:
        time.sleep(.5)
        bi1()
def play1(): #first built in animation
    print "Type in 'q' at any time possible to return to the main menu, or 'b' to go to     the animations menu."
    bi1()
def animations1(): #pre made animations
    print "You are now viewing the pre-made animations."
    time.sleep(1)
    print "During each animation, hold down enter for the animation to play, or type     'q' then enter to quit."
    time.sleep(1)
    animation_choice = raw_input("Type in '1' for animation 1, '2' for animation 2, or     'q' to go back to the main menu.: ")
    if animation_choice1 == "1":
        play1()
    elif animation_choice1 == "2":
        play2()
    elif animation_choice1 == "q":
        main_menu()
    else:
        print "Invalid choice, check spelling and try again."
        animations1()
def main_menu():
    print "Type in 'q' to quit the program."
    print "Type in 'v1' to choose between 2 pre-made animations."
    print "Type in 'as' to go to the animation studio."
    print "Type in 'v2' to view your custom animations."
    choice = raw_input("Or type in 'b' to go back to the explaination of this program.:     ")
    if choice == "b":
        explaination()
    elif choice == v1:
        animations1() #animations1 is the pre-made one
    elif choice == "as":
        animation_studio()
    elif choice == "v2":
        animations2() #animations2 is the custom user-made animations
    elif choice == "q":
        quitcheck = raw_input("Are you sure you would like to exit the program?     (type 'y' or 'n'): ")
        if quitcheck == "y":
            print "Goodbye."
            time.sleep(2)
        elif quitcheck == "n":
            main_menu()
        else:
            print "Invalid choice (check spelling/case), returning to main menu    ..."
            time.sleep(1)
            main_menu()
    else:
        print "Invalid choice, please check your spelling and try again."
        main_menu()

def explaination():
    print "Welcome to the animation viewer/maker!"
    time.sleep(1)
    print "In the main menu, you can select what you would like to do."
    time.sleep(1)
    print "This program uses text characters to animate something in a loop."
    time.sleep(1)
    print "As long as you don't close this program, it can save 2 different custom     animations, and you can view the ones you created or the pre-made ones."
    time.sleep(1)
    print "With custom animations, you can type anything you want to create animations     that loop (see the pre-made ones for ideas/examples). They can be up to 10 lines."
    time.sleep(1)
    jafsdlk = raw_input("Please press enter to continue.: ")
    main_menu() 
explaination()

我可能复制了错误的代码,但我不知道。 无论如何,iu还没有添加动画工作室或制作和保存自定义动画的能力,它是一个非常简单的程序类型。 但当我把它放在记事本中并将其保存为.py文件并运行它来测试它时,我开始得到一个错误,当它运行explainination()时,它说它有一个错误的三重引用字符串,但如果我做带有一个引号的三重引用字符串,它在扫描文字时给了我EOL,有人帮助

1 个答案:

答案 0 :(得分:1)

反斜杠\是一个转义字符。您通常使用它,因此Python将逐字地使用下一个字符。

您可以在字符串前加r来表示原始字符串,或者用三重引号将其括起来,就像您已经完成的那样。但是,您遇到的问题是\在您的行的近三重引号中转义第一个",这会使三个引号打开它,只有两个要关闭 - 这使得它在下一行中寻找下一个",它会抛弃其他一切。

右:

print r"This works because there's a space after the slash \ "

错:

print r"This doesn't \"

https://docs.python.org/2.7/reference/lexical_analysis.html#string-literals