커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
eng_quiz.py
[무료] 1시간 만에 정복하는 코딩테스트 합격법 v0
1주차
북마크
h***l
댓글
2
추천
0
조회수
51
조회수
51
답변 완료

* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.

* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.



# "8zerothree2" → 8032
# "seven73nine" → 7739
# "two53eightfour" → 25384

s1 = "8zerothree2"
s2 = "seven73nine"
s3 = "two53eightfour"

def solution(s):
    num_dict = {
        "zero": "0",
        "one": "1",
        "two": "2",
        "tree": "3",
        "four": "4",
        "five": "5",
        "six": "6",
        "seven": "7",
        "eight": "8",
        "nine": "9",
    }
    for str in num_dict:
        s = s.replace(str, num_dict[str])
    answer = int(s)
    return answer

print(solution(s1))
print(solution(s2))
print(solution(s3))


강의를 보면서 파이참에서 eng_quiz.py 코드를 작성하고 실행했는데 아래와 같은 에러가 나옵니다.





"C:\Users\yj\Desktop\workspace\Algorithm Notes\venv\Scripts\python.exe" "C:\Users\yj\Desktop\workspace\Algorithm Notes\Algorithm\eng_quiz.py" 
Traceback (most recent call last):
  File "C:\Users\yj\Desktop\workspace\Algorithm Notes\Algorithm\eng_quiz.py", line 27, in <module>
    print(solution(s1))
          ^^^^^^^^^^^^
  File "C:\Users\yj\Desktop\workspace\Algorithm Notes\Algorithm\eng_quiz.py", line 24, in solution
    answer = int(s)
             ^^^^^^
ValueError: invalid literal for int() with base 10: '80three2'


Process finished with exit code 1

취소
 공유
취소
댓글 0
댓글 알림
나의얼굴