2013-10-29 3 views
-1

목록에서 두 개의 이름에 액세스하여 아래의 dead() 함수에 표시하려고합니다. 터미널에는 % s 및 % s 만 표시됩니다. 나는 파이썬리스트에있는 문서를 읽었지만, 내가 잘못하고있는 것을 볼 수 없다.목록에서 이름에 액세스하여 표시하는 방법

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

귀하의 괄호는 dead() 함수 호출이 줄의 끝으로 이동해야 닫을 수 :

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]) 

이 내 죽은() 함수 내 코드입니다. 그렇지 않으면 문자열 보간은 입력이 아닌 반환 값에서 발생합니다.

너의 :

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])) 
+0

정말 고맙습니다. 위대한 작품! – lol5433

0

형식은 괄호 안에 있어야합니다. 그대로 형식은 dead()에서 반환에 적용됩니다.

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