from datetime import date calculations = ['1.0 km = 1000.0 m', '500.0 m = 50000.0 cm', '2.5 km = 2500000.0 mm', '100.0 cm = 1.0 m', '250.0 mm = 25.0 cm'] # ***** Get current date for heading and filename **** today = date.today() # Get day, month and year as individual strings day = today.strftime("%d") month = today.strftime("%m") year = today.strftime("%Y") file_name = f"distances_{day}_{month}_{year}" write_to = f"{file_name}.txt" with open(write_to, 'w') as text_file: text_file.write("***** Distance Calculations *****\n") text_file.write(f"Generated: {day}/{month}/{year}\n\n") text_file.write("Here is your calculation history (oldest to newest)...\n") # write each item to file for item in calculations: text_file.write(item) text_file.write("\n")