Python Forum
Christmas and other occasions
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Christmas and other occasions
#1
I am trying to make a program that can tell people the date and time (I have done this bit) but I want to add to the program, I want a way to detect the date and then display a little message depending on the date.

e.g.

#if date == 25/12
#print("Merry christmas!")
and

#if date == 1/1
#print("Happy new year!")
etc.
etc.
Reply
#2
import datetime

today = datetime.date.today()

if (today.day, today.month) == (15, 7):
    print('today is 15th day and 7th month')
else:
    print('you have run this code on a different day')
Output:
today is 15th day and 7th month
Reply
#3
(Jul-15-2019, 08:19 PM)Yoriz Wrote:
import datetime

today = datetime.date.today()

if (today.day, today.month) == (15, 7):
    print('today is 15th day and 7th month')
else:
    print('you have run this code on a different day')
Output:
today is 15th day and 7th month

Ok then thanks!
Reply
#4
Holidays are complicated. I'd recommend just using a list someone else made, such as this one: https://github.com/dr-prodigy/python-holidays
Reply
#5
(Jul-15-2019, 09:13 PM)nilamo Wrote: Holidays are complicated. I'd recommend just using a list someone else made, such as this one: https://github.com/dr-prodigy/python-holidays

I am only trying to implement set holidays, (Christmas lands on the 25th every year)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Christmas Tree (Why is it like that ?) GaivSo 2 1,617 Dec-17-2020, 03:44 PM
Last Post: GaivSo
  Help me write a Christmas Program! marienbad 3 2,350 Dec-26-2018, 12:57 PM
Last Post: marienbad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020