Posts

Showing posts from January, 2018

validation write and date time

from datetime import datetime def insertintofile (name , age , address): date = datetime.now() file= open ( "file.txt" , "w" ) file.write( "name:" + name + " \n " ) file.write( "age:" + age + " \n " ) file.write( "address:" + address + " \n " ) file.write( "date and time :" + str (date) + " \n " ) file.close def view (): file= open ( "file.txt" , "r" ) print (file.read()) file.close() 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" ) valid_characters = "1234567890" while True : age = input ( &

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 numbers def input_age (message): while True : try : userInput= int ( input (message)) except ValueError : print ( "not an integer! Try again." ) continue else : return userInput break age= 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