Skip to content

Add input validation for age field #13028

@Shweyy123

Description

@Shweyy123

Feature description

def get_age_input():
age_input = input("Enter your age: ")
if age_input.isdigit():
age = int(age_input)
print(f"Your age is {age}")
else:
print("age is not valid")

get_age_input()

What this does:

  1. Takes input from the user.

  2. Checks if the input only contains digits using .isdigit().

  3. If it is digits, it converts it to an int and prints it.

  4. If it’s not (e.g., letters, special characters), it prints "age is not valid".

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementThis PR modified some existing files

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions