강의로 돌아가기
Choi Jae Hun

파이썬 4,8,9,12,14 통과가 안되네요 ㅠ

뭐가 문제 일까요?? ㅠㅠ
위에 예시들 런타임에러가 뜹니당,,

작성중인 코드―solution.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
def solution(s):
    answer = 0
    bowl_list = []
    bowl = ''
    for i in range(len(s)):
        if s[i].isdigit() == True or s[i] == 'Z' or s[i] == '-':
            bowl += s[i]
        elif s[i] == ' ':
            if bowl == 'Z':
                bowl_list.append(bowl)
            else:
                bowl_list.append(int(bowl))
            bowl = ''
    if bowl.isdigit() == True:
        bowl_list.append(int(bowl))
    else:
        bowl_list.append(bowl)
    for j in range(len(bowl_list)):
        if bowl_list[j] != 'Z':
            answer += bowl_list[j]
        else:
            answer -= bowl_list[j-1]


    return answer
1 개의 답변
정현호

주어지는 값의 마지막 숫자가 음수의 경우

14번 줄에서 isdigit()이 False로 나오고 bowl_list에 str 타입으로 값이 들어가기 때문에

22번 줄 answer에 값을 더할 때 int + str 이여서 에러가 발생합니다.

  • Choi Jae Hun

    진짜 감사합니다 선생님

    Choi Jae Hun―Jan 05, 2023 10:08
답변 쓰기
This input form supports markdown syntax. Please refer to 마크다운 가이드.