Skip to content

Improve Age Input Validation & Edge Case Handling #3

@subh0100

Description

@subh0100

The current voting eligibility program handles ValueError for non-numeric input. However, it does not properly handle some edge cases such as:
Negative age values
Extremely large unrealistic ages
Zero as input
Blank input
This may lead to incorrect logical output (e.g., negative wait years).
⚠️ Problem

If the user enters:
-5 → Output becomes: Wait 23 more years ❌
0 → Logic technically works but may need validation
150 → No upper bound validation

✅ Expected Behavior

Age should not be negative.
Age should have a reasonable upper limit (e.g., 120).
Program should show a proper error message for invalid age ranges.
Improve user input validation for better robustness.💡 Suggested Improvement
Add range validation inside the try block:
if age < 0 or age > 120:
print("Please enter a realistic age between 0 and 120.")

🎯 Acceptance Criteria

Prevent negative age input
Prevent unrealistic age input
Maintain existing ValueError handling
Clean and readable code

you can find the code in voting.py file

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestgood first issueGood for newcomersquestionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions