파이썬 'int' object has no attribute 'isdigit'
조회수 500회
score = int(input("Enter your score: "))
if not score < 0:
if score.isdigit():
if score > 100 and score < 0:
grade = '0~100사이'
else:
grade = 'asd'
else:
grade = '숫자로 입력해주세요'
else:
grade = '음수는 입력이 불가'
print(grade)
- 에러1 음수
- 에러2 숫자범위
- 에러3 문자열불가 이렇게 만들려고 하는데
'int' object has no attribute 'isdigit'
라고 정수형 형태가 안맞는 에러가(?) 나와요. 어느부분에서 형태수정해야할지좀 알려주시와요.
1 답변
-
isdigit이 문자열을 검사하는 명령이라서 그럴 겁니다. 애초에 문자열이 입력되면 int 변환 작업에서 에러가 발생합니다. 다음과 같이 구성해보세요.
score = input("점수를 입력해주세요. : ") try: score = int(score) except: raise Exception('숫자로 입력해주세요') if not score < 0: if score > 100 and score < 0: grade = '0~100사이입니다.' else: grade = '음수가 입력되었습니다.' print(grade)
댓글 입력