Skip to content

Add validate_age script to other folder #12835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions other/validate_age.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""
This script prompts the user to input their age
and validates that it is a non-negative integer.
"""


def get_valid_age() -> int:
"""
Continuously prompts user for a valid age input until a non-negative integer is provided.

Check failure on line 9 in other/validate_age.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

other/validate_age.py:9:89: E501 Line too long (93 > 88)

Returns:
int: The validated age input.
"""
while True:
age = input("Enter your age: ")
if age.isdigit():
num = int(age)
if num < 0:
print("Age can't be negative.")
else:
return num
else:
print("Invalid input. Please enter a valid number.")


if __name__ == "__main__":
age = get_valid_age()
print(f"Your age is {age}")
Loading