Identifying and Correcting Errors
도입됨
6:10
창작적 개발
두 수의 평균을 출력해야 하는 프로그램이 있습니다. 실행됩니다. 충돌하지 않습니다. 답을 출력하지만 답은 틀립니다.给它四和六(Give it four and six—주어진 텍스트는 영어로 되어 있으므로 번역: 네와 여섯을 주면)…
영어 내레이션 · 영어와 중국어 자막 전환 가능
이 수업의 내용
| English | 의미 |
|---|---|
| bug/bʌɡ/ | 버그 |
| debugging/ˈdiːbʌɡɪŋ/ | 디버깅 |
| syntax error/ˈsɪntæks ˈerə/ | 구문 오류 |
| logic error/ˈlɒdʒɪk ˈerə/ | 논리 오류 |
| runtime error/ˈrʌntaɪm ˈerə/ | 런타임 오류 |
| overflow error/ˌəʊvəˈfləʊ ˈerə/ | 오버플로우 오류 |
| edge case/edʒ keɪs/ | 경계 사례 |
| expected output/ekˈspektɪd ˈaʊtpʊt/ | 예상 출력 |
모든 프로그램에는 버그가 있다
- 팀이 아무리 신중하더라도 프로그램에는 실수가 포함됩니다.
- 프로그램 내의 실수를 **버그(bug)**라고 합니다.
- 버그를 찾아 수정하는 작업을 **디버깅(debugging)**이라고 합니다.
- 숙련된 디버깅 능력은 프로그래머가 쌓을 수 있는 가장 가치 있는 기술 중 하나입니다.
Which kind of error?
A syntax error stops the program running; a logic error runs but gives the wrong answer; a runtime error crashes it partway; an overflow error exceeds storage.
The work of finding and fixing mistakes in a program is called ______.
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
A mistake is a bug; fixing bugs is debugging.
A missing bracket that stops the program from running is a:
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
Breaking the language's rules is a syntax error.
Why are logic errors often the hardest to find?
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
Nothing obviously breaks, so you must compare output to what you expected.
주요 오류 종류
- **구문 오류(syntax error)**는 언어 규칙 위배(예: 괄호 누락)로 프로그램 실행이 거부됩니다.
- **논리 오류(logic error)**는 실행되지만 지시사항이 계획과 일치하지 않아 잘못된 결과를 출력합니다.
- **실행 중 오류(runtime error)**는 실행 중 프로그램이 충돌하는 것—영으로 나누기 같은 경우입니다.
- **오버플로우 오류(overflow error)**는 값이 저장 공간보다 너무 커질 때 발생합니다.

trace table은 버그를 찾기 위해 프로그램이 실행될 때 각 변수의 값을 기록함

Testing with edge cases (empty input, very large numbers) helps find hidden bugs.
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
Bugs often hide at the limits of what a program expects.
To spot a bug in a test, you compare the actual output with the:
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
A difference between actual and expected output points to a bug.
찾는 방법
- 다양한 입력으로 테스트하세요. 이상한 경우, 매우 큰 숫자, 빈 입력, 또는 한계치에 해당하는 경계 조건(edge case) 등도 포함해야 합니다.
- 실제 출력과 예상(output expected) 출력 비교; 차이가 있으면 버그를 의미합니다.
- 내부 값을 확인하기 위해 임시 출력 문장을 추가하여 어디서 처음 잘못되는지 찾으세요.
- 분할 및 검증(divide and check): 일부가 올바른지 확인한 뒤 나머지를 좁혀가며 점검하세요.
After fixing a bug, you only need to re-test the line you changed.
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
False. A fix can create a new bug elsewhere, so you should re-test the whole program after changing it.
수정 후 재테스트
- 논리 오류는 가장 어렵습니다. '고장 난' 것이 분명하지 않고, 답만 틀린 것입니다.
- 하나의 버그를 수정하면 다른 버그를 만들 수도 있습니다.
- 따라서 모든 수정 후 전체 프로그램을 재테스트해야 합니다.
- 세심하고 반복적인 테스트가 거친 프로토타입을 사람들이 신뢰할 수 있는 소프트웨어로 만듭니다.
"실행되었다"가 "올바르다"와 같습니다. 논리 오류는 충돌이나 메시지 없이 실행되므로 프로그램이 정상처럼 보이지만 답은 틀립니다. 이를 잡으려면 단순히 실행되었는지 확인하는 것이 아니라, 출력물을 예상된 내용과 비교해야 합니다.
이 카드는 새로 추가되어 번역이 준비될 때까지 영어로 표시됩니다.
Worked example: finding a logic error
A program should find the average of a list of test scores. For the list [80, 90, 70] it prints 60 instead of 80. The code adds each score to a sum, then divides the sum by (length of list + 1). Classify and fix the bug.
- The program runs and prints a result, so it is not a syntax or runtime error: it is a logic error. Checking by hand: the sum is 240, and $240\div(3+1)=60$, so the divisor is wrong.
- Fix: divide by the length of the list: $240\div3=80$. Then test with more cases, including an edge case such as an empty list, which would cause a runtime error (division by zero) unless the program checks for it first.
A program crashes with "division by zero" when the user enters 0. This is:
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
It happens while the program is running.
Testing only typical inputs is enough to find most bugs.
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
Edge cases and unusual inputs reveal many bugs.
**버그(bug)**는 오류를 뜻하며, 버그를 수정하는 것을 **디버깅(debugging)이라고 합니다. 구문 오류 syntax error는 프로그램 실행을 중단시키고, 논리 오류 logic error는 실행되지만 잘못된 결과를 내놓으며, ** runtime 오류 runtime error는_execution 중 crash_하고, 오버플로우 오류 overflow error는 저장 공간을 초과합니다. 버그는 다양한 입력(특히 경계 조건 edge cases)을 기대되는 출력 expected output과 대조하여 테스트함으로써 찾아낼 수 있으며, 수정 후에는 반드시 재테스트 re-test해야 합니다.
어떤 문제가 있었나요? 사이트 팀만 이 내용을 볼 수 있습니다.