2016-08-02 3 views
1
print("Welcome to the Age Classifier program") 
person_age=(float(input("Enter the person's Age")) 

if person_age<=1 or person_age>0: 
     print("Person is an infant") 
elif person_age>1 or person_age<13: 
     print("Person is a child") 
elif person_age>=13 or person_age<20: 
     print("Person is a teenager") 

elif person_age>=20 : 
     print("Person is an adult") 
else: 
     print("Person has not been conceived or is developing in the womb") 

, 인터프리터는 if 문의 몸의 1 라인에 오류 메시지가 구문이 잘못되었음을보고와 함께,이 있음을보고합니다. 나는 괄호를 추가하려고 시도하고 동일한 구문 오류가 발생했습니다.나이 분류 파이썬 프로그램은

+1

이 경우 입력이 -1 인 경우에도 "Person is infant"가 출력됩니다. –

답변

1

당신은 불균형 괄호있다.

person_age=(float(input("Enter the person's Age")) # 3 opening, 2 closing. 

:

person_age=int(input("Enter the person's Age")) 
+2

덕분에, 분명히 우리가 도움을 줄 수 –

+0

다행 음수를하지 않는 수레. –

2

첫 번째 줄에 오류가 괄호에 주로 기인한다 :

person_age=float(input("Enter the person's Age")) 

아마이 정수하기 위해,하지만, 더 좋은 생각이 될 것입니다 이것을 다음으로 변경하십시오 :

person_age=(float(input("Enter the person's Age"))) 

또한 논리 오류가 있습니다. 조건 중 하나에 해당하는 경우 or 연산자는 True를 반환합니다. 나는 당신의 유스 케이스에 어울리는지 의심 스럽다.

if person_age<=1 and person_age>0: 
     print("Person is an infant") 
elif person_age>1 and person_age<13: 
     print("Person is a child") 
elif person_age>=13 and person_age<20: 
     print("Person is a teenager") 
elif person_age>=20 : 
     print("Person is an adult") 
else: 
     print("Person has not been conceived or is developing in the womb") 
관련 문제