-1

リストから 2 つの名前にアクセスして、以下の dead() 関数に表示しようとしています。端末には %s と %s のみが表示されます。Python リストに関するドキュメントを読みましたが、何が間違っているのかわかりません。

from sys import exit

name = ["Max", "Quinn", "Carrie"]

def start():
    print """
    There are a bunch of people beating at the door trying to get in.
    You're waking up and a gun is at the table.
    You are thinking about shooting the resistance or escape through out the window.
    What do you do, shoot or escape?
    """
    choice = raw_input("> ")

    if choice == "shoot":
        dead("You manage to get two of them killed, %s and %s, but you die as well.") % (name[1], name[2])

これは私のデッド()関数の私のコードです:

def dead(why):
    print why, "Play the game again, yes or no?"

    playagain = raw_input()

    if playagain == "yes":
        start()
    elif playagain == "no":
        print "Thank you for playing Marcus game!"
    else:
        print "I didn't get that, but thank you for playing!"
    exit(0)
4

2 に答える 2

4

関数呼び出しを閉じる括弧はdead()、行末に移動する必要があります。それ以外の場合、文字列補間は入力ではなく戻り値で発生しています。

あなたのもの:

dead("You manage to get two of them killed, %s and %s, but you die as well.") % (name[1], name[2])

修理済み:

dead("You manage to get two of them killed, %s and %s, but you die as well." % (name[1], name[2]))
于 2013-10-29T20:17:04.180 に答える
0

形式は括弧内にある必要があります。そのままで、フォーマットは からの戻り値に適用されますdead()

dead("You manage to get two of them killed, %s and %s, but you die as well." % (name[1], name[2]))
于 2013-10-29T20:17:30.870 に答える