2013-06-25 21 views
-4

behavioural_level은 raw_input 1, 2 또는 3으로 정의됩니다.
여기에 무슨 일이 일어나고 있습니까?NONE을 반환합니다. 내가 중첩되어 있습니까?

def summary_behaviour(x): 
    if behaviour_level == 1: 
     x = random.randint(0,1) 
     if x == 0: 
      return " "+str(first_name)+" has a rather "+str(shy[random.randint(0,(len(shy)-1))])+" personality. This has certain advantages. One is that "+str(he_she(gender))+" doesn't easily "+str(lose_focus[random.randint(0,(len(lose_focus)-1))])+": however, "+str(he_she(gender))+" can be a litte quiet at times." 
     else: 
      if x == 1: 
       return " Because of "+str(first_name)+"'s "+str(shy[random.randint(0,len(shy)-1)])+" character "+str(he_she(gender))+" can be a little quiet sometimes. On the plus side, however, "+str(he_she(gender))+" doesn't "+str(lose_focus[random.randint(0,len(lose_focus)-1)])+" very easily." 
    elif behaviour_level == 2: 
     x = random.randint(2,3) 
     if x == 2: 
      return str(first_name)+" is usually quite "+str(loud[random.randint(0,(len(loud)-1))])+" in class, and this has advantages and disadvantages. "+str(first_name)+" loves to involved and enjoys speaking, but sometimes "+str(hes_shes(gender))+" too "+str(loud[random.randint(0,(len(loud)-1))])+" to fully concentrate. This is common though. " 
     else: 
      if x == 3: 
       return " Because of "+str(first_name)+"'s "+str(loud[random.randint(0,len(loud)-1)])+" character "+str(he_she(gender))+" is "+str(adjective(int(science_level)))+" at speaking up and volunteering. Occasionally, "+str(his_her(gender))+" "+ str(loud[random.randint(0,len(loud)-1)])+ " nature can cuase "+str(him_her(gender))+ " to "+str(lose_focus[random.randint(0,len(lose_focus)-1)])+" but, that's fairly normal at "+str(his_her(gender))+" age." 
    else: 
     if behaviour_level == 3: 
      x = random.randint(4,5) 
      if x == 4: 
       return " I would descirbe "+str(fisrt_name)+" as a "+(str(well_mannered[random.randint(0,len(well-mannered)-1)]))+" child who is easy to teach. Rarely is "+str(he_she(gender))+" too "+str(loud[random.randint(0,(len(loud)-1))])+" to focus or too "+str(shy[random.randint(0,(len(shy)-1))])+" too speak up." 
      else: 
       if x == 5: 
        return str(first_name)+" a "+ (str(well_ma 

답변

4

중첩이 좋습니다.

raw_input()은 문자열을 반환합니다. 함수가있는 경우/다른 문장의 첫 번째 else: 비트가됩니다 있도록 behaviour_level != 1이 (오히려 그것이 "1"와 동일) 때문에, 정수로 변환 한 것처럼

다음, if behaviour_level == 3:을 보이지 않는다. 입력이 정수가 아닌 문자열이므로 not True입니다. else이 없으므로이 함수의 기본값은 None입니다.

이 문제를 해결하려면 문자열을 정수로 변환하는 int() 함수를 사용할 수 있습니다.

1

당신은
int(behaviour_level) == 1,2 or 3
1 2 3 문자열을 반환 정수와 raw_input을 그대로
을 비교하는 데 사용할 수 있습니다.


또한, 대신

else: 
    if condition: 
    """statements""" 

을하는 당신은 간단하게 사용할 수 있습니다

elif condition: 
    """statements""" 
관련 문제