Validation & verification · אישור וביצוע בדיקות
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.
מדוע לבצע אימות נתונים
- אימות בודק שהנתנים הנכנסים הם סבירים לפני שהתוכנה משתמשת בהם.
- "פרשזל נכנס, פרשזל יוצא" — נתונים גרועים מובילים לתשובות שגויות.
- התוכנה מחליטה אם לקבל או דחות את הערך.
The validation steps · שלבי האישור
Read the input, check it, then accept or reject — bad data never gets used. · קרא את הקלט, בדוק אותו, ולאחר מכן קבל או דחה — נתונים לא תקינים לעולם אינם משמשים.
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")
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")
Presence check
- A presence check makes sure something was actually entered.
- An empty string
""means the user typed nothing.
בדיקת נוכחות
- בדיקת נוכחות וודאת שנכנס מידע באמת.
- מחרוזת ריקה
""מציינת שהמשתמש לא הקליד כלום.
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.
בדיקת אמינות: בדיקת העתקה
- בדיקת אמינות בודקת שהנתונים הועתקו או הוקלדו נכון.
- בדיקת כפולה מבקשת מהמשתמש להזין את הערך פעמיים ומשווה ביניהם.
- בדיקה ויזואלית פירושה שאדם קורא אותה חזרה ממסך המחשב.
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
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.
טעויות נפוצות
- בדיקות אימות בודקות שהנתונים סבירים (טווח, אורך, סוג); בדיקות אמינות בודקות שהם הוזנו נכון.
- בדיקת טווח דורשת גבול תחתון וגבול עליון.
Now you try
- Each function returns
Trueto accept orFalseto reject. - Press Check answer to test your code.
כעת תנסו בעצמכם
- כל פונקציה מחזירה
Trueלקבלה אוFalseלדחייה. - לחץ על בדוק תשובה כדי לבדוק את הקוד שלך.
Write valid_age(a) that returns True when a is a sensible age (0 to 120 inclusive), otherwise False. This is a range check. · כתוב valid_age(a) שתחזיר True כאשר a הוא גיל סביר (0 עד 120 כולל), אחרת תחזir False. זוהי בדיקת טווח.
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. · כתוב valid_password(p) שתחזir True כאשר הסיסמה היא באורך 8 תווים לפחות. זוהי בדיקת אורך.
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. · כתוב is_present(s) שתחזir True כאשר נכנס מידע כלשהו, ותחזir False למחרוזת ריקה "". זוהי בדיקת נוכחות.
Click Run to see the output here. · לחץ על הרץ כדי לראות את התוצא כאן.