2014-12-26 2 views
-1

scenario2 (결과) 함수는 sget_choice3을 호출하므로 사용자 선택에 따라 결과를 인쇄합니다.입력을 두 번 묻지 않는 동안

사용자 선택이 0 인 경우 루프를 실행하고 입력을 두 번 요청합니다 (올바른 것은 1이고 0은 그 분기입니다).

문제는이 줄 것으로 보인다
s2option_list3 =['Try to force it', 'Examine the door'] 

    def sget_choice3(s2option_list3): 
     i = -1 
     while i <= 0: 
      print s2option_list3 
      choice3 = raw_input("> ") 
      for i, opt in enumerate(s2option_list3): 
       if opt in choice3: 
        i = i + 1 
        return i 
       else: 
        i = i + 2 
        return i    

      print "You need to select one of the given actions" 

def scenario2_exit(outcome): 
    print outcome 
    choice = outcomes[0] 

    if outcome in choice: 
     print "conversation" 

     res3 = sget_choice3(s2option_list3) 

     if res3 == 0: 
      print "You try to force it but without any luck. However you do notice a little button on the left corner. " 

     else: 
      print "A small panel comes out, seems to be requesting a code. " 
      print "conversation"    

    else: 
     print "conversation" 
+1

: 뭔가처럼 당신에게 당신의 프로그램을 재구성하는 방법에 너무 많은 조언을 제공하지 않고

는 간단한 수정 될 수 있습니다. 우리가 제공하는 답변에서 뭔가를 배웠던 때가 아닙니까? –

+0

같은 질문이 아닙니다. –

답변

1

:

for i, opt in enumerate(s2option_list3): 

당신이 그런 enumerate를 사용

, 그것은 열거의 인덱스 (시 -1) i에 대한 값을 덮어 쓰기한다 (첫 번째 옵션은 0이고 두 번째 옵션은 1입니다. 왜 열거 형을 사용하려고하는지 모르겠습니다. 당신은 매일 거의 거의 같은 질문을했습니다

for opt in s2option_list3: 
관련 문제