“elif”语法错误

时间:2016-08-06 19:08:02

标签: python syntax-error

我正在建立一个游戏,让计算机知道你想到的哪种农场动物。他问你猜问你的农场动物的问题。但我收到了一个错误,我不知道如何解决它。

我的代码:

qs_one = raw_input("Do your animal walk on two legs? answar 'yes' or 'no'")
if qs_one == "yes":
    qs_two = raw_input("Do your animal have a white skin? answar 'yes' or 'no'")
    if qs_two == "yes":
        print "Your animal is a goose!"
    elif qs_two == "no":
        print "Your animal is a chicken!"
    else:
        print "Error, try again."
elif qs_one == "no":
    qs_two = raw_input("Do your animal have horns? answar 'yes' or 'no'")
    if qs_two == "yes":
        qs_tree = raw_input("Do your animal have stains? answar 'yes' or 'no'")
        if qs_tree == "yes":
            print "Your animal is a cow!"
        elif qs_tree == "no":
            qs_four = raw_input("Do your animal have goatee? answar 'yes' or 'no'")
            if qs_four == "yes":
                print "Your animal is a goat!"
            elif qs_four == "no":
                print "Your animal is a bull!"
            else:
                print "Error, try again."
        else:
            print "Error, try again."
    elif qs_two == "no":
        qs_tree = raw_input("Do your animal have a pink skin? answar 'yes' or 'no'")
        if qs_tree == "yes":
            print "Your animal is a pig!"
        elif:  # <- ERROR HERE
            qs_four = raw_input("Can you ride your animal? answar 'yes' or 'no'")
            if qs_four == "yes":
                print "Your animal is a horse!"
            elif qs_four == "no":
                qs_five = raw_input("Does your animal have big ears? answar 'yes' or 'no'")
                if qs_five == "yes":
                    "Your animal is a rabbit!"
                elif qs_five == "no":
                    "Your animal is a sheep!"
                else:
                    print "Error, try again."
            else:
                print "Error, try again."
        else:
            print "Error, try again."
    else:
        print "Error, try again."
else:
    print "Error, try again."

错误:

Traceback (most recent call last):
File "python", line 30
elif:
    ^
SyntaxError: invalid syntax``

1 个答案:

答案 0 :(得分:4)

你需要有elif的条件,即

elif condition_is_true:
    *do something*

我认为你想要做的是使用elif qs_tree=='no':。如果“是”,那就是猪,如果“不”,那就是别的,其他每一个答案都应该给出“错误,再试一次” - 消息。