Watch the explanation. Practice the skill.

Python for AI work

Write a small Python program that rejects invalid input.

Visual lesson1:38

Captions appear here during playback.

Python for AI work

Write a small Python program that rejects invalid input.

Download transcriptOpen video file

Source-based teaching example · Fictional data · Reviewed 2026-10-03. Microsoft Mark · locally synthesized. On a small screen, use fullscreen for diagram details or read the transcript.

Read the descriptive transcript

0:00 · What you will learn

Write a small Python program that rejects invalid input.

What appears on screen

Write a small Python program that rejects invalid input.

0:06 · 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.

What appears on screen

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.

0:19 · One useful term

Input validation. Checking input against the rules before using it.

What appears on screen

Checking input against the rules before using it.

0:27 · 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.

What appears on screen

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.

0:42 · Your turn to think

Should every exception be turned into a successful greeting? Pause and decide before continuing.

What appears on screen

Should every exception be turned into a successful greeting? Pause the video if you need more time.

0:58 · 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.

What appears on screen

No. Keep invalid input visibly different from success. Record the run command and Python version, or label a paper trace as unexecuted.

1:11 · Check 1

Test the limit and the case beyond it.

What appears on screen

Test the limit and the case beyond it.

1:16 · Check 2

Keep errors distinct from normal output.

What appears on screen

Keep errors distinct from normal output.

1:22 · Check 3

Record how you ran the program.

What appears on screen

Record how you ran the program.

1:27 · 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.

What appears on screen

Open the lesson Try the new case Check and revise The full task and its requirements are in the linked lesson.

Watching explains the example. Complete the lesson practice to check what you can do. Explore all visual lessons →