Validation & verification
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · 이 페이지는 최신 브라우저(SharedArrayBuffer 지원)가 필요합니다. Chrome, Edge, Firefox 또는 Safari를 최신 버전으로 업데이트해 주세요.
English
Why validate input
- Validation checks that input is sensible before the program uses it.
- "Garbage in, garbage out" — bad data leads to wrong answers.
- The program decides to accept or reject the value.
한국어
입력 값 검증이 필요한 이유
- 검증은 프로그램이 데이터를 사용하기 전에 입력값이 적절하고 타당한지 확인합니다.
- "나쁜 데이터가 들어오면 나쁜 결과가 나온다" — 잘못된 데이터는 오답으로 이어집니다.
- 프로그램은 해당 값을 수용하거나 거부할지 결정합니다.
Explore · 탐색하기
The validation steps
Read the input, check it, then accept or reject — bad data never gets used.
English
Range check
- A range check makes sure a number is between a low and a high limit.
- Example: a month must be from 1 to 12.
한국어
범위 검사
- 범위 검사는 숫자가 낮은 한계치와 높은 한계치 사이에 있는지 확인합니다.
- 예: 월은 1부터 12까지여야 합니다.
month = 13
if 1 <= month <= 12:
print("Accepted")
else:
print("Rejected")
English
Length check
- A length check makes sure text is not too short or too long.
len(text)gives the number of characters.
한국어
길이 검사
- 길이 검사는 텍스트가 너무 짧거나 너무 길지 않은지 확인합니다.
len(text)는 문자 수를 반환합니다.
password = "abc"
if len(password) >= 8:
print("Accepted")
else:
print("Too short")
English
Presence check
- A presence check makes sure something was actually entered.
- An empty string
""means the user typed nothing.
한국어
존재 여부 검사
- 존재 여부 검사는 실제로 입력값이 들어왔는지 확인합니다.
- 빈 문자열
""는 사용자가 아무것도 입력하지 않았음을 의미합니다.
English
Verification: checking the copy
- Verification checks that data was copied or typed correctly.
- A double-entry check asks for the value twice and compares them.
- A visual check means a human reads it back on screen.
한국어
검증: 복사본 확인
- 검증은 데이터가 올바르게 복사되거나 입력되었는지 확인합니다.
- 이중 입력 확인은 값을 두 번 입력하게 하여 비교합니다.
- 시각적 확인은 사람이 화면에서 내용을 다시 읽는 것입니다.
English
In the exam: types of check
- Know these validation checks: range, length, type, presence, format, check digit.
한국어
시험: 확인의 유형
- 이러한 검증 확인을 기억하세요: 범위, 길이, 형식, 존재 여부, 포맷, 체크 디ジット.
IF Age >= 0 AND Age <= 120
THEN
OUTPUT "Valid"
ELSE
OUTPUT "Invalid"
ENDIF
English
Common mistakes
- Validation checks data is sensible (range, length, type); verification checks it was entered correctly.
- A range check needs both a lower and an upper limit.
한국어
흔한 실수
- 검증은 데이터가 합리적인지(범위, 길이, 형식) 확인하고, 확인은 올바르게 입력되었는지 확인합니다.
- 범위 확인에는 하한과 상한 모두 필요합니다.
English
Now you try
- Each function returns
Trueto accept orFalseto reject. - Press Check answer to test your code.
한국어
이제 직접 해보기
- 각 함수는 수락을 위해
True를, 거부를 위해False를 반환합니다. - Answer 확인 버튼을 눌러 코드를 테스트하세요.
Write valid_age(a) that returns True when a is a sensible age (0 to 120 inclusive), otherwise False. This is a range check.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.
Write valid_password(p) that returns True when the password is at least 8 characters long. This is a length check.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.
Write is_present(s) that returns True when something was entered, and False for an empty string "". This is a presence check.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.