Python for AI work Write a small Python program that rejects invalid input. Reviewed: 2026-10-03 Source-based teaching example · Fictional data Narration: Microsoft Mark · locally synthesized 00:00:00.000 — What you will learn Write a small Python program that rejects invalid input. Visual description: Write a small Python program that rejects invalid input. 00:00:06.583 — The idea Start with a clear rule for valid input. Test a valid case and cases that must fail. A program should not hide an error by returning a normal-looking answer. Visual description: Start with a clear rule for valid input. Test a valid case and cases that must fail. A program should not hide an error by returning a normal-looking answer. 00:00:19.708 — One useful term Input validation. Checking input against the rules before using it. Visual description: Checking input against the rules before using it. 00:00:27.250 — A worked example The greeter accepts nonempty text with a 100-character limit. A 101-character input must fail. Put the length check after the blank-input check and test both failures. Visual description: The greeter accepts nonempty text with a 100-character limit. A 101-character input must fail. Put the length check after the blank-input check and test both failures. 00:00:42.042 — Your turn to think Should every exception be turned into a successful greeting? Pause and decide before continuing. Visual description: Should every exception be turned into a successful greeting? Pause the video if you need more time. 00:00:58.917 — Why this answer works No. Keep invalid input visibly different from success. Record the run command and Python version, or label a paper trace as unexecuted. Visual description: No. Keep invalid input visibly different from success. Record the run command and Python version, or label a paper trace as unexecuted. 00:01:11.583 — Check 1 Test the limit and the case beyond it. Visual description: Test the limit and the case beyond it. 00:01:16.708 — Check 2 Keep errors distinct from normal output. Visual description: Keep errors distinct from normal output. 00:01:22.208 — Check 3 Record how you ran the program. Visual description: Record how you ran the program. 00:01:27.083 — Now try a different case Open the lesson and try its different practice case. Use every check in the full task. Watching alone does not mark the lesson complete. Visual description: Open the lesson Try the new case Check and revise The full task and its requirements are in the linked lesson.