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("enter your age")
    if all(int in valid_characters for int in age):
        print("your age is:" + age)
        break    print("That's invalid, please try again. Please enter number only")


enter your name khai
your name is:khai
enter your age12
your age is:12
enter your addressasv 
your name is:asv 
name:khai
age:12
address:asv 
date and time :2018-01-25 14:03:39.296643


Process finished with exit code 0

Comments

Popular posts from this blog

WD&D (DNS)

kclothings.org

WDD-LO1-server