Aug-22-2019, 05:30 PM
def check_id(): while True: id = input("Please enter your ID: ") if len(id) == 8 and ' 'not in id and id[0:2].isalpha()==True and id[2:8].isdigit()==True: print("Thanks for the input") return id else: print("Input must have only 8 characters and should not have whitespaces,the first 2 characters must be alphabets,please re-enter your ID") def check_name(): while True: name = input("Please provide your name: ") if len(name)!=0 and name.replace(" ","").isalpha() and name[0:1] is not ' ': print("Thanks for the input") return name else: print("The name entered is an empty string or has whitespaces or has characters other than alphabets,please re-enter your name") def check_Doctor(): while True: name = input("Please provide the name of the doctor you would like to book an appointment with: ") if len(name)!=0 and name.replace(" ","").isalpha() and name[0:1] is not ' ': print("Thanks for the input") return name else: print("The name entered is an empty string or has whitespaces or has characters other than alphabets,please re-enter the Doctor's name") def check_date(): from datetime import datetime while True: inputdate = input("Please enter date in DDMMYYY format: ") ApptDateReq = datetime.strptime(inputdate, "%d/%m/%Y") present = datetime.now() if ApptDateReq.date() > present.date(): print("Thanks") return inputdate else: print("You cannot book an appointment in the past,please re-enter date") def check_phone(): while True: phone = input("Please provide your phone number: ") if all((len(phone) == 10, phone.isdigit())): print("Thanks for the input,you have entered",phone) return phone else: print("The phone number entered is an empty string or has whitespaces or has alphabets,please re-enter the phone number") import datetime from datetime import datetime n = 5 while n > 0: id = check_id() with open("C:\\Users\\abc\\Def\\" "%s.txt" % id, "a") as file: name = check_name() Doctor = check_Doctor() ApptDate = check_date() phone = check_phone() EmailID = input("Please provide your email to confirm your appointment: ") dtstamp = datetime.today().strftime('%Y-%m-%d %H:%M:%S') file.write(name+ "|" +Doctor+ "|" +ApptDate+ "|" +EmailID+ "|" +phone+ "|" +dtstamp+ "\n") MoreData = input("Do you need to make any new Appointments? y/n :") if MoreData != "y": n= -1How do I autoemail the text file which is created as an attachment once the user clicks y or n to the email
Stored in ‘Email’
Thanks