data validation

how to do validation on python 
code 
# khairah, version python3, 24 Jannuary 2018
valid_characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "while True:
    name = input("Enter Your Name")
    if all(char in valid_characters for char in name):
     print("your name is:" + name)
     break    print("That's invalid, please try again. Please enter characters A-Z and space only")

# validating numbersdef input_age(message):
    while True:
        try:
            userInput=int(input(message))
        except ValueError:
            print("not an integer! Try again.")
            continue        else:
            return userInput
            breakage= input_age("How old are you?")
print("you are" + str(age) + "years old")



output 
Enter Your Name khairah 
your name is: khairah 
How old are you? 12
you are12years old

Process finished with exit code 0

Comments

Popular posts from this blog

WD&D (DNS)

kclothings.org

WDD-LO1-server