From 179900c04cfa64299207d6c3e43c2ec3108825d3 Mon Sep 17 00:00:00 2001 From: tmiklu <61796331+tmiklu@users.noreply.github.com> Date: Sat, 16 Jan 2021 19:54:32 +0100 Subject: [PATCH] Change memory compare --- days/01-03-datetimes/code/datetime_date.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/days/01-03-datetimes/code/datetime_date.py b/days/01-03-datetimes/code/datetime_date.py index 05bc842f..27dab6c1 100644 --- a/days/01-03-datetimes/code/datetime_date.py +++ b/days/01-03-datetimes/code/datetime_date.py @@ -2,6 +2,7 @@ from datetime import datetime from datetime import date +from sys import intern datetime.today() #datetime.datetime(2018, 2, 19, 14, 38, 52, 133483) @@ -31,11 +32,13 @@ #19 -christmas = date(2018, 12, 25) -christmas -#datetime.date(2018, 12, 25) +christmas = date(date.today().year, 12, 25) -if christmas is not todaydate: +# This function allows you to compare their memory addresses rather than comparing the strings character-by-character: +a = intern(str(todaydate)) +b = intern(str(christmas)) + +if a is not b: print("Sorry there are still " + str((christmas - todaydate).days) + " until Christmas!") else: print("Yay it's Christmas!")