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.
في الامتحان: أنواع الفحوصات
- اعرف هذه فحوصات التحقق (Validation): النطاق، الطول، النوع، الوجود، الصيغة، رقم التحقق.
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 شاملاً)، وإلا ترجع 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) تُرجع 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) تُرجع True عندما تم إدخال شيء ما، وتُرجع False لسلسلة فارغة "". هذا فحص الوجود.
Click Run to see the output here. · اضغط تشغيل لرؤية المخرجات هنا.