Data Validation Patterns
Range Checks
Numeric validation keeps values inside the range a program is prepared to handle.
range check
A range check compares a value against lower and upper bounds and returns a clear decision.
Range Checks
range_check.py
Replay: real traced execution (multi-file project)
def status_for_age(age):
if age < 18:
return "too_young"
if age > 120:
return "too_high"
return "ok"
age = 30
status = status_for_age(age)
print(f"age={age}:{status}")
def status_for_age(age):
if age < 18:
return "too_young"
if age > 120:
return "too_high"
return "ok"
age = 17
status = status_for_age(age)
print(f"age={age}:{status}")
age ← 30
9age→ 30 = 30 #@age=1710status = status_for_age(age30)def status_for_age(age):
1def status_for_age(age30):2 if age < 18:3 return "too_young"4 if age > 120:5 return "too_high"6 return "ok"status ← ok
9age = 30 #@age=1710status→ ok = status_for_age(age30)1112print(f"age={age30}:{statusok}")outputage=30:ok
age ← 17
9age→ 17 = 1710status = status_for_age(age17)def status_for_age(age):
1def status_for_age(age17):2 if age < 18:3 return "too_young"if age < 18:
1def status_for_age(age):2 if age17 < 18:3 return "too_young"4 if age > 120:status ← too_young
9age = 1710status→ too_young = status_for_age(age17)1112print(f"age={age17}:{statustoo_young}")outputage=17:too_young