Validation with write and date and time

Output
Coding

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:" + str(age) + "\n")
    file.write("Address:" + address + "\n")
    file.write("Date and Time:" + str(date) + "\n")
    file.close()

def view():
    view = open("file.txt", "r")
    print(view.read())
    view.close()

validcharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "while True:
    name = input("Enter your name:")
    if all(char in validcharacters 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")


def input_number(message):
    while True:
        try:
            age = int(input(message))
        except ValueError:
            print("Not an integer! Try again.")
            continue        else:
            return age
            break

age = input_number("How old are you?")
print("You are " + str(age) + " years old")

address = input("Enter your address:")
print("You lived in " + str(address))



insertintofile(name, age, address)
view()

Comments

Popular posts from this blog

WAN Technology

LO3 - Know the features and functions of information systems

WDD - LO1 - MANAGE SECURE SITES